TCPDF page borders?
Asked Answered
O

5

5

I'm trying to achieve simple 1px solid red border around each page generated in TCPDF. Previously using other PDF scripts I was forced to draw a rectangle after doing some rough calculations with getting the page width and height and -20px (to allow for 10px indentation on each side). However I'm unsure how I can achieve a similar result with TCPDF.

Does anyone have any experience?

Overflow answered 10/2, 2011 at 10:27 Comment(0)
S
9

Here you go (this will draw a black line of 15 points around the current page)

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));

$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
Sadism answered 21/11, 2012 at 18:11 Comment(0)
G
4

Use Rect:

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Rect(0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());
Genarogendarme answered 12/9, 2017 at 12:51 Comment(0)
P
3
$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
$pdf->SetLineStyle( array( 'width' => 14, 'color' => array(255,255,255)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
Phenolic answered 27/5, 2017 at 7:5 Comment(0)
F
1

You can use the TCPDF Line function and create four lines around each side of the page.

Far answered 31/1, 2012 at 15:4 Comment(0)
A
0

Try like this:

public function Header()
{
    $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);
    
    $this->SetLineStyle( array('width'=>0.40,'color'=> array(0,0,0)));
    
    $this->Line(5,5, $this->getPageWidth()-5,5);
    
    $this->Line($this->getPageWidth()-5,5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5,5,5, $this->getPageHeight()-5);
}
Atalayah answered 12/10, 2021 at 6:55 Comment(1)
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Granivorous

© 2022 - 2024 — McMap. All rights reserved.