如何在HTML中插入分页符,以便wkhtmltopdf对其进行解析? [英] How to insert a page break in HTML so wkhtmltopdf parses it?

查看:443
本文介绍了如何在HTML中插入分页符,以便wkhtmltopdf对其进行解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我是使用wkhtmltopdf将动态HTML报告转换为PDF.

So basically I'm using wkhtmltopdf to convert a dynamic HTML report to PDF.

该报告具有特定的格式,并且已要求我使用HTML克隆该格式.

The report has a particular format and I've been asked to clone that format with HTML.

我面临的问题是我无法在html中模拟100%功能的分页符,因此wkhtmltopdf可以解释它并将内容发送到另一页.

The problem I'm facing is that I can't simulate a 100% functional page break in html so wkhtmltopdf can interpret it and send content to another page.

我正在尝试避免使用页面尺寸测量方法等等.

I'm trying to avoid page size measurement methods and so.

TIA提供的任何帮助.

TIA for any help provided.

到目前为止,我正在使用<br>模拟分页符,并且可以使用.我仍然需要做一些测试.

So far I'm emulating page break using <br> and it works. I still have to do some testing though.

推荐答案

指定特定于打印介质类型的CSS规则.有许多可用于分页的属性.我发现将page-break-before属性附加到类上最简单,如下所示.

Specify a CSS rule specific to the print media type. There are a number of properties that can be used for paging. I find it easiest to attach the page-break-before property to a class, as shown below.

在HTML中:

<p>Page 1, paragraph 1</p>
<p class="new-page">Page 2, paragraph 1</p>
<p>Page 2, paragraph 2</p>

在CSS中:

@media print {
  .new-page {
    page-break-before: always;
  }
}

这篇关于如何在HTML中插入分页符,以便wkhtmltopdf对其进行解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆