TCPDF How to set top margin in header

10,276

you can try this

.....
$margin = $this->getMargins();
$this->SetY($margin['top']);
.....

The method getMargins() returns an array containing current margins. for more information you can access at http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b

Share:
10,276
mlewis54
Author by

mlewis54

Updated on July 25, 2022

Comments

  • mlewis54
    mlewis54 almost 2 years

    I am having an issue with TCPDF in that I am trying to set the Y value for the first line of text to be printed on the page after the header has been output and it's being ignored. My header routine is in an extended TCPDF class as follows:

    public function Header() {
                    $this->setJPEGQuality(90);
                    $this->Image('/www/images/hdrlogo.gif', 5, 20, 150, 0, 'GIF', 'https://www.example.com');
                    $this->SetFont(PDF_FONT_NAME_MAIN, 'B', 14);
                    $this->SetY(23);
                    $this->cell(0,20,"Activity Report",0,0,"R");
                    $this->SetFont(PDF_FONT_NAME_MAIN, 'R', 11);
                    $when=date("m/d/Y");
                    $this->SetY(41);
                    $this->cell(0,20,"Prepared $when",0,0,"R");
                    $this->Line(170,43,587,43);
                    $this->SetY($this->topMargin);           
            }
    

    Regardless of the value in $this->topMargin the Y value is unaffected after the header has been output. The reason I need to set the Y value is that when a HTML overflows the page I need to have the overflow text start on the page after the header information. The headers look fine on the page. Is this the correct way to do this or is there another way within TCPDF?