本文介绍了Mpdf:仅将第1页的页边距设置为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$mpdf = new \Mpdf\Mpdf([
        'tempDir' => __DIR__ . '/temp'
    ]);
$mpdf->SetMargins(0, 0, 0); // will set it to 0 for all pages.

PDF页面的第1页的页边距是否为0,文档的其余页面的页边距是否为默认页边?

Is it possible to have 0 margins for page 1 of a PDF page and default margins for the rest of pages of the document ?

我目前正在使用7.0版对此进行测试.

I'm currently testing this with Version 7.0.

推荐答案

如果不需要页面1和其他页面的自动内容溢出,则可以使用 AddPageByArray() 方法:

If you do not need automatic content overflow for page 1 and other pages, you can use AddPageByArray() method:

$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.

在首页出现内容溢出的情况下,下一个自动创建的页面的页边距也为零.

In a case of content overflow from the first page, the next, automatically created page will also have zero margins.

或者,您可以在构造函数中设置零页边距,并使用 <pagebreak> 伪HTML标记:

Alternatively, you can set zero margins in the constructor and reset margins for following pages using <pagebreak> pseudo-HTML tag:

$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);

这篇关于Mpdf:仅将第1页的页边距设置为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 03:27