How to enable automatic page break in mpdf in php?

Member

by lily , in category: PHP General , a year ago

How to enable automatic page break in mpdf in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , a year ago

@lily 

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:

1
2
3
4
5
6
7
8
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().