WeasyPrint始终从Zurb Ink生成单页PDF [英] WeasyPrint always generating single-page PDFs from Zurb Ink
本文介绍了WeasyPrint始终从Zurb Ink生成单页PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从电子邮件生成PDF(以Zurb墨水为模板);但始终只显示一页PDF.
Generating a PDF from an email (Zurb Ink templated); but am always presented with a single page PDF.
可运行的测试用例:
from weasyprint import HTML, CSS
from urllib2 import urlopen
if __name__ == '__main__':
html = urlopen('http://zurb.com/ink/downloads/templates/basic.html').read()
html = html.replace('<p class=\"lead\">', '{0}<p class=\"lead\">'.format(
'<p class=\"lead\">{0}</p>'.format("foobar " * 50) * 50))
HTML(string=html).write_pdf('foo.pdf', stylesheets=[
CSS(string='@page { size: A4; margin: 2cm };'
'* { float: none !important; };'
'@media print { nav { display: none; } }')
])
如何获取多页PDF?
推荐答案
<body>
<!-- this is the container div -->
<div>
Content
</div>
</body>
如果您的html具有以上结构,则weasyprint会尝试将所有容器"内容放入一页.
If your html has the above structure then weasyprint will try to fit all of your 'container'content in one page.
我现在想到的第一个解决方案是:将html分成2个单独的div-s.每个div不得超过页面大小.
First solution I have in mind right now: split your html in 2 separate div-s. Each div should be no longer than the page size.
更新 每当您希望文档中有分页符时,请尝试添加此内容.
Update Try adding this whenever you wish to have a page-break in your document.
<p style="page-break-before: always" ></p>
这篇关于WeasyPrint始终从Zurb Ink生成单页PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文