【问题标题】:WeasyPrint always generating single-page PDFs from Zurb InkWeasyPrint 总是从 Zurb Ink 生成单页 PDF
【发布时间】:2014-07-15 20:14:49
【问题描述】:

从电子邮件生成 PDF(Zurb Ink 模板);但总是呈现单页 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?

【问题讨论】:

    标签: css pdf multipage zurb-ink weasyprint


    【解决方案1】:

    更新答案:

    只要您希望在文档中添加分页符,请尝试添加它。

    <p style="page-break-before: always" ></p>
    

    旧答案:

    <body>
    <!-- this is the container div -->
      <div>
        Content
      </div>
    </body>
    

    如果您的 html 具有上述结构,那么 weasyprint 将尝试将您的所有“容器”内容放在一个页面中。

    我现在想到的第一个解决方案:将您的 html 拆分为 2 个单独的 div-s。每个 div 的长度不应超过页面大小。

    【讨论】:

    • &lt;p style="page-break-before: always" &gt;&lt;/p&gt; 为我工作
    • - 这对我也有用,非常感谢。
    • 你拯救了我的一天!谢谢!
    • 这对我不起作用,我的高度标签取决于我在 render_template(x, yyy) 中提供的参数
    • 你救了我的命!感谢您的更新!
    猜你喜欢
    • 2018-03-26
    • 2021-08-23
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    相关资源
    最近更新 更多