TCPDF set bottom margin zero

TCPDF set bottom margin zero

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

TCPDF Zero Bottom Margin: A Practical Guide

When generating PDFs with TCPDF, the default behavior includes substantial margins around the printable area. While standard page margins are often sufficient for documents requiring headers and footers, there are scenarios where data must be pushed to the absolute bottom edge of the page. This is common when generating receipts, labels, or specific report formats where whitespace at the base of the page is undesirable.

The user's initial attempt addresses this by setting $pdf->SetFooterMargin(0) and disabling the footer with setPrintFooter(false). However, these actions only affect the vertical space reserved for the footer region; they do not alter the physical boundary of the page itself. In TCPDF, the "bottom margin" is technically controlled by the main page configuration, distinct from the footer-specific settings.

To truly eliminate the space at the bottom of the page, you must manipulate the page margins directly using SetPageMargins. The standard approach involves creating a PDF instance and immediately configuring its margins to zero before adding content.

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

// Set default margin to 0 for all sides
$pdf->SetMargins(14, 6, 0); 

// Disable headers and footers to prevent interference with edge content
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// Optional: Disable page breaks if you are managing layout manually
$pdf->setAutoPageBreak(TRUE, 0); 

The critical line here is $pdf->SetMargins(14, 6, 0). The first two arguments correspond to the left and top margins, while the third argument specifically defines the right margin. To achieve a zero bottom margin, you must pass 0 as the fourth parameter if using a four-argument signature, or rely on the default behavior if only three are provided in specific versions. In modern TCPDF iterations, the method signature typically follows $pdf->SetMargins($left, $top, $right). The bottom margin is often handled implicitly by the page break logic.

However, simply setting the left and top margins does not automatically collapse the bottom space unless you also manage the internal page break settings. By default, TCPDF reserves a specific amount of space at the bottom to prevent content from spilling into the footer area (even if the footer is disabled). To force content to sit flush against the physical edge, you need to ensure that the internal buffer for the bottom margin is effectively zeroed out.

This can be achieved by calling $pdf->SetAutoPageBreak(false, 0) before adding your HTML or text. When automatic page breaking is disabled, TCPDF stops calculating reserved spaces at the bottom of the page based on standard breakpoints. Instead, it allows content to render until the very last available pixel defined by your page dimensions minus the explicit left and top margins you set.

There is a significant trade-off to consider when removing all margins: alignment with printers. Most physical printers have hardware limitations; they cannot print perfectly up to the edge of the paper due to mechanical constraints or ink bleeding. If you generate a PDF with zero margins and send it directly to a standard printer, the content may appear cut off or washed out on the bottom edge.

If your use case involves printing via TCPDF's internal driver (e.g., for a web-to-print workflow where the client handles the spooling), zero margins are safe. If you are generating PDFs for direct consumer printing, you should verify the printer's specifications. Some printers offer "borderless" or "edge-to-edge" print modes that can handle these constraints, while others will physically cut off content within 2mm of the edge regardless of the PDF settings.

Another potential pitfall involves the SetFooterMargin property. While setting this to 0 removes the footer's internal padding, it does not remove the page's bottom margin. The footer margin is distinct from the page margin. If you require content that visually overlaps where a footer would normally be (even without rendering a footer), you must ensure the page bottom margin itself is zeroed via SetMargins.

In summary, to achieve a PDF with no space at the bottom in TCPDF:

  1. Initialize the PDF instance.
  2. Call $pdf->SetMargins($left, $top, 0) (or omit the third argument if using the standard 3-parameter version where the right margin is default and bottom is handled via the next step).
  3. Disable auto page break or set it to a value that respects your custom margins: $pdf->setAutoPageBreak(false, 0).
  4. Disable headers and footers if they are not needed.

This configuration allows data to be written directly against the bottom boundary of the page dimensions. For complex layouts involving multiple pages where you want varying margins per page, TCPDF allows calling SetMargins again after AddPage(), though this is rarely necessary for simple zero-margin documents. If you are building a library or a reusable component for invoice generation, wrapping these settings in a helper method ensures consistency across your application without repeating the boilerplate code every time.

Our network