$mpdf = new \Mpdf\Mpdf([
'tempDir' => __DIR__ . '/temp'
]);
$mpdf->SetMargins(0, 0, 0); // will set it to 0 for all pages.
是否可以为 PDF 页面的第 1 页设置 0 页边距,并为文档的其余页面设置默认页边距?
我目前正在使用 7.0 版对此进行测试。
最佳答案
如果不需要第1页和其他页面的自动内容溢出,可以使用 AddPageByArray()
方法:
$mpdf = new \Mpdf\Mpdf([]);
$mpdf->AddPageByArray([
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'margin-bottom' => 0,
]);
$mpdf->WriteHTML($html1); // first page
$mpdf->AddPageByArray([
'margin-left' => '15mm',
'margin-right' => '20mm',
'margin-top' => '15mm',
'margin-bottom' => '15mm',
]);
$mpdf->WriteHTML($html2); // other pages
// All other pages will then have margins of the second `AddPageByArray()` call.
在内容从第一页溢出的情况下,下一个自动创建的页面也将具有零边距。
或者,您可以在构造函数中设置零边距并使用
<pagebreak>
重置后续页面的边距。伪 HTML 标签:$mpdf = new \Mpdf\Mpdf([
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
]);
$html = 'Content of the first page
<pagebreak margin-left="15mm" margin-right="15mm" margin-top="15mm" margin-bottom="20mm">
Other content';
$mpdf->WriteHTML($html1);
关于php - Mpdf : Set 0 margin for page 1 only,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49920397/