How to enable automatic page break in mpdf in php?


by lily , in category: PHP General , 5 months ago

How to enable automatic page break in mpdf in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , 5 months ago


To enable automatic page breaks in mPDF in PHP, you will need to set the autoPageBreak property to true.

Here's an example of how to enable automatic page breaks using mPDF:

require_once __DIR__ . '/vendor/autoload.php'; // Include mPDF autoload file

$mpdf = new MpdfMpdf(); // Initialize mPDF object
$mpdf->autoPageBreak = true; // Enable automatic page breaks

// Rest of your code...

$mpdf->Output(); // Output the PDF document

By default, mPDF will set autoPageBreak to true, so this step may not be necessary if you have not explicitly set it to false elsewhere in your code. However, it is good practice to explicitly set it to true to ensure that automatic page breaks are enabled.

Note that you may also need to adjust the margins, headers, and footers to allow space for the automatic page breaks and maintain the desired layout. These settings can be adjusted through various methods in mPDF, such as SetMargins(), SetHeader(), and SetFooter().