Html 打印html时如何定义分页符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21269836/
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-29 00:37:32  来源:igfitidea点击:

How to define page breaks when printing html?

htmlprintingreport

提问by Please_Dont_Bully_Me_SO_Lords

I have a application made with Delphi 2006 which prints with QuickReport. Due to many bugs, I will rebuild this section of the software , generating the report in HTML and then send it to printer through some component. My question is, How/Can I tell when printer should break into a new page with HTML? Some tag or event on printing component for HTML?

我有一个用 Delphi 2006 制作的应用程序,它用 QuickReport 打印。由于很多bug,我将重新构建该软件的这一部分,生成HTML格式的报告,然后通过某些组件将其发送到打印机。我的问题是,如何/我可以知道打印机何时应该使用 HTML 进入一个新页面?HTML 打印组件上的某些标记或事件?

回答by EStafford

You can add page breaks for printing with a little bit of CSS.

您可以使用一点 CSS 为打印添加分页符。

CSS:

CSS:

@media all {
.page-break { display: none; }
}

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

HTML: Use a div element with the page-break class where you want insert your breaks

HTML:将 div 元素与要在其中插入中断的分页符类一起使用

<div class="page-break"></div>

Example:

例子:

<div>Some content BEFORE the page break</div>
<div class="page-break"></div>
<div>Some content AFTER the page break</div>
<div class="page-break"></div>
<div> ... More content after another page break ... </div>