I'm dynamically generating PDFs with an unknown page count. mPDF is working good, but the top margin on the second page is gone. How can I set the margins for all pages with the document?
I've tried the following, but it has no effect:
$mpdf = new mPDF('', '', 0, '', 15, 15, 15, 15, 8, 8);
In standard usage, mPDF sets the following: margin-top = distance in mm from top of page to start of text (ignoring any headers) margin-header = distance in mm from top of page to start of header. margin-bottom = distance in mm from bottom of page to bottom of text (ignoring any footers)
// Define a page size/format by array - page will be 190mm wide x 236mm height $mpdf = new \Mpdf\Mpdf(['format' => [190, 236]]); The format is an array of width and height in millimeters. Save this answer.
php $mpdf->AddPage(); You can define or change all page characteristics when you add the new page: orientation. margins.
mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.
You can use something like this. it seems to work.
define the margins using @page like:
<?php
include("mpdf.php");
$html='<style>@page {
margin: 0px;
}</style>
';
$mpdf=new mPDF('','A4');
$mpdf->WriteHTML($html);
$mpdf->Output();
?>
I was able to find an answer. Here it is in case anyone needs it:
define the margins using @page
like:
@page *{
margin-top: 2.54cm;
margin-bottom: 2.54cm;
margin-left: 3.175cm;
margin-right: 3.175cm;
}
</style>';
Reference: http://www.mpdf1.com/forum/discussion/80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With