【发布时间】:2017-02-17 21:54:00
【问题描述】:
我正在使用 WeasyPrint 在 Django 中生成 PDF。我可以从如下所示的静态 html 文件生成 pdf -
from django.template import Context, Template
import weasyprint
with open('static_file.html', 'r') as myfile:
html_str = myfile.read()
template = Template(html_message)
context = Context({'some_key': 'some_value'})
rendered_str = template.render(context)
weasyprint.HTML(string=rendered_str).write_pdf('generated.pdf')
但我想生成一个 PDF,我可以在每个页面中包含一个通用的页眉/页脚并添加分页。
如果有人能告诉如何包含自定义字体来生成 PDF,这将非常有帮助。我已经在操作系统(Ubuntu 14.04)中安装了字体,但它不工作。
我在网上搜索了很多关于这些的内容。但找不到合适的解决方案。
【问题讨论】:
标签: python django fonts pagination weasyprint