Search code examples
tcpdf

Why does TCPDF put text on following page?


When I set

$pdf = new dmdpdf("P", "IN","USLETTER", true, 'UTF-8', true);  // US Letter page size

and say

$pdf->text (1.0,10.3,'Test');

the text is printed at the top of the next page.

However, if I say

 $pdf = new dmdpdf("P", "IN", "USLEGAL", true, 'UTF-8', true); // US Legal page size

The text is printed exactly where I want it, within the margin of a USLetter page.

I can work around this be setting the page as USLEGAL but I am wondering if I am missing something. For the sake of purity, I'd like to do it without a fiddle.


Solution

  • US Letters are 11 inches tall.

    The default page break margin is 20 mm from the bottom of the page, which would be 0.73 inches. 11-0.73 = 10.27. That puts your test text just beyond that automatic break position, so it triggers the automatic page break.

    Set your page break margin to something smaller (or disable it entirely). If this is for a footer, consider using a custom footer instead.

    I'm not familiar with dmdpdf but if it's a thin wrapper around TCPDF use setAutoPageBreak

    /**
     * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
     * @param $auto (boolean) Boolean indicating if mode should be on or off.
     * @param $margin (float) Distance from the bottom of the page.
     * @public
     * @since 1.0
     * @see Cell(), MultiCell(), AcceptPageBreak()
     */
    public function SetAutoPageBreak($auto, $margin=0)