php DOMpdf,向PDF添加新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22746958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:13:37  来源:igfitidea点击:

DOMpdf, adding a new page to PDF

phpdompdf

提问by Kitalpha

Is it possible to add a new page in DOMpdf? Similar to mPDF AddPage(); functionaly. I can't seem to find anything in the documentation, is there any work around to this?

是否可以在 DOMpdf 中添加新页面?类似于 mPDF AddPage(); 功能性的。我似乎在文档中找不到任何内容,是否有任何解决方法?

I can't seem to find anything in the documentation.

我似乎无法在文档中找到任何内容。

回答by BrianS

dompdf takes care of paging automagically. If you want to force a page break you can do so by styling an element with page-break-before: always;or page-break-after: always;.

dompdf 自动处理分页。如果你想强制分页,你可以通过使用page-break-before: always;或 来设置元素的样式page-break-after: always;

回答by cottton

Just an example for BrianS's answer:

只是 BrianS回答的一个例子:

CSS

CSS

.page_break { page-break-before: always; }

HTML

HTML

<div class="page_break"></div>

回答by Didier Sampaolo

If the other answer doesn't work for you (as it is for me), you can add a CSS class :

如果另一个答案对您不起作用(就像对我一样),您可以添加一个 CSS 类:

.page { width: 100%; height: 100%; }

and encapsulate every "page" in an element with this class. Not the prettiest way, but it does the job.

并使用此类将每个“页面”封装在一个元素中。不是最漂亮的方式,但它可以完成工作。

回答by Andresa Martins

All answers presented here will make DomPDF to add a blank page to the end of the PDF file. Here is how to fix that:

此处提供的所有答案将使 DomPDF 在 PDF 文件的末尾添加一个空白页。以下是解决此问题的方法:

CSS:

CSS:

div.page_break + div.page_break{
    page-break-before: always;
}

HTML:

HTML:

<div class="page_break"></div>