javascript 将html打印到多页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27929014/
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
Print html to multiple page
提问by ConfusedUser
Assuming we have multiple html paragraph
假设我们有多个 html 段落
<p>Paragraph 1</p>
<p>Paragraph 2</p>
Is there a way to print both to different page to the printer ?
有没有办法将两者打印到打印机的不同页面?
Paragraph 1 would be printed on the first page and Paragraph 2 would be printed on the second page.
第 1 段将打印在第一页上,第 2 段将打印在第二页上。
Thank You
谢谢
回答by antyrat
You can do this using CSS page-break-after
property:
您可以使用 CSSpage-break-after
属性执行此操作:
@media print {
p { page-break-after: always; }
}
It will print each p
element on new page.
它将p
在新页面上打印每个元素。
window.print()
@media print {
@page { margin: 0; }
p { page-break-after: always; }
}
<p>Paragraph 1</p>
<p>Paragraph 2</p>