【发布时间】:2020-06-25 03:01:37
【问题描述】:
我在使用 mpdf 时遇到了这个问题,如果某些文本到达页面的最后一行,它将创建一个额外的空白页面。
我已经尝试了一百万件事,但似乎无法弄清楚这一点。我想要一个可靠的方法来确保我的 pdf 中没有空白页。
所以,我想知道是否有一个 {PAGEEND} 标记或我在我的 html 中放置的某个标记让 mPDF 知道这是页面的结尾,并且不要在此页面之后创建页面。我在文档中没有看到任何关于此的内容。
这是我的 mpdf 配置中的内容:
$mpdf = new \Mpdf\Mpdf([
'format' => 'A4',
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 6,
'margin_bottom' => 20,
'margin_header' => 5,
'margin_footer' => 5
]);
if ( isset( $_REQUEST['css_files'] ) ) {
$css_files = $_REQUEST['css_files'];
if ( is_array($css_files) ) {
foreach ( $_REQUEST['css_files'] as $cssurl ) {
$stylesheet = file_get_contents($cssurl);
$mpdf->WriteHTML($stylesheet,1);
}
}
}
$mpdf->useSubstitutions = false; // optional - just as an example
$mpdf->simpleTables = false;
$mpdf->SetAuthor("My Website");
$mpdf->SetDisplayMode('fullpage');
$mpdf->setAutoBottomMargin = 'stretch';
$mpdf->SetHTMLFooter('<div width="90%" align="right">{PAGENO}</div>');
$mpdf->setBasePath($url);
$mpdf->WriteHTML( $html );
$mpdf->Output($title . ".pdf", 'D'); exit;
我将 margin-bottom 设置为 20mm,这样内容就不会与我的页脚冲突。
css_files 是从我的模板接收的数组。 css 文件是网站样式和打印样式表。我正在加载它们并将它们应用到页面。
我已经尝试在我的 print.css 上洒page-break-after: avoid;,但我仍然得到那个讨厌的额外空白页。
我还清理并清除了任何额外的底部边距,但这似乎没有帮助。
【问题讨论】:
标签: mpdf