简体   繁体   English

如何在使用 wkhtmltopdf 将 html 转换为 pdf 之前确定页面的结尾?

[英]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.

相关问题 如何在转换为pdf之前设计html页面? - How to design html page before converting to pdf? 通过 wkhtmltopdf 将包含 openlayers 映射的 html 页面转换为 pdf - Converting html page containing openlayers map to pdf via wkhtmltopdf 如何使用wkhtmltopdf获取html生成的pdf中的页码 - How to get page numbers in pdf generated by html with wkhtmltopdf 打印HTML时,如何确定页面末尾还有多少空间? - When printing HTML, how can I determine how much space is left before the end of the page? 尝试使用wkhtmltopdf将html文件转换为pdf - Trying to convert an html file to pdf using wkhtmltopdf 如何在使用 jsPDF 将 html 转换为 pdf 时在 pdf 中的某个点进行分页? - How to give page break at certain point in pdf while converting html to pdf using jsPDF? 如何使用PDF.js确定PDF的自然页面大小 - How to determine natural page size of a PDF using PDF.js html转pdf:html内容溢出时如何动态添加页面到pdf? (动态多页 pdf) - Converting html to pdf: how to dynamically add pages to pdf when html content is overflowing? (dynamic multiple page pdf) 将 HTML 转换为 PDF 时如何在每页底部添加页脚 - How to add footer to bottom of each page when converting HTML to PDF 如何使 pdf 的高度和宽度与 html 相同,同时使用 html? - How to make the pdf height and width same as html while converting html to pdf using html2pdf?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM