[英]How to determine an end of a page before converting html to pdf using wkhtmltopdf?
I have an HTML page that is generated dynamically, based on a specific form.我有一个基于特定表单动态生成的 HTML 页面。 Once an HTML page is generated, it can be converted to PDF using
wkhtmltopdf
.生成 HTML 页面后,可以使用
wkhtmltopdf
将其转换为 PDF。
If the page is too long, wkhtmltopdf
will automatically split it into multiple pages, but I want to have control over WHERE the split will happen.如果页面太长,
wkhtmltopdf
会自动将其拆分为多个页面,但我想控制拆分发生的位置。
I need this because each page will contain specific charts for the specific information that will be displayed on the page and whenever automatic split happens, I sometimes get a chart not being related to the text displayed on the page.我需要这个,因为每个页面都将包含将显示在页面上的特定信息的特定图表,每当发生自动拆分时,我有时会得到一个与页面上显示的文本无关的图表。
So ideally I want to be able to determine whether the form generated content is too long for 1 page or not and then manually add a new page with controlled content.所以理想情况下,我希望能够确定表单生成的内容对于 1 页是否太长,然后手动添加一个包含受控内容的新页面。
To add a new page, I'm basically using the following CSS rule, which works fine:要添加新页面,我基本上使用以下 CSS 规则,它工作正常:
@media print {
.new-page {
page-break-before: always;
}
}
The application is built in Laravel
+ Svelte.js
(but I don't think it matters much, because I'm just trying to figure out how to approach the issue in general).该应用程序是用
Laravel
+ Svelte.js
(但我认为这并不重要,因为我只是想弄清楚如何解决这个问题)。
Perhaps I could get some recommendations?也许我可以得到一些建议?
To control where to split your page, you can use the page-break-after attribute.要控制在何处拆分页面,您可以使用page-break-after属性。
Example :例子 :
<div style="page-break-after:always;"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.