如何在PhantomJS中处理PDF分页 [英] How to handle PDF pagination in PhantomJS

查看:595
本文介绍了如何在PhantomJS中处理PDF分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PhantomJS从html创建PDF.

I am using PhantomJS to create PDFs from html.

它可以正常工作,但是我找不到如何分页的方法;我想为文档中的每个div创建一个页面,但是在文档中找不到任何内容.关于分页.

It works fine, but I can't find out how to work with pagination; I want to create a page for each div in my document, but I can't find anything in the doc. about pagination.

如果我的文档很短,那么它只能打印一页,如果我的文档比较大,它会创建一个空白页面,而我的内容位于第一页,这会变得很长.

If my document is short, it makes only one page, and if it is bigger, it creates one second empty page and my contents are in the first page which becomes very long.

有什么主意吗? (我将phantomJS-node模块用于nodeJS)

Any idea ? (I am using phantomJS-node module for nodeJS)

推荐答案

PhantomJS负责webkit的CSS实现.要实现手动分页符,您可以使用以下属性:

PhantomJS takes care of webkit’s css implementation. To implement manual page breaks you can use these properties :

  • page-break-before:自动/始终/避免/...
  • page-break-inside:自动/始终/避免/...
  • page-break-after:自动/始终/避免/...
  • page-break-before : auto/always/avoid/...
  • page-break-inside : auto/always/avoid/...
  • page-break-after : auto/always/avoid/...

例如,一个div可以是:

For example, a div can be :

 <div style="page-break-before:always;"><!-- content --></div>

<div style="page-break-after:always;"> <!-- content --></div>

在Webkit中打印时控制分页符有时并不容易,尤其是对于长html表而言.

Controlling page breaks when printing in Webkit is sometimes not easy, in particular with long html tables.

这篇关于如何在PhantomJS中处理PDF分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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