首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
›
Django Project
›
Django REST Framework
V2EX
›
Django
django xhtml2pdf 如何写入 CSS 和图片
askask
·
2016-04-19 16:54:22 +08:00
· 3558 次点击
这是一个创建于 3108 天前的主题,其中的信息可能已经有所发展或是发生改变。
from xhtml2pdf import pisa
html = '<html><body><p><h1>To PDF </h1>or <h2>not to PDF</h2><p></body></html>'
outputFilename = 'test.pdf'
def convertHtmlToPdf(html, outputFilename):
resultFile = open(outputFilename, "w+b")
pisaStatus = pisa.CreatePDF(html,dest=resultFile)
resultFile.close()
return pisaStatus.err
if __name__=='__main__':
pisa.showLogging()
convertHtmlToPdf(html, outputFilename)
求助。如果 HTML 当中有 CSS 和图片如何写入到 PDF 了?
HTML
PDF
pisa
xhtml2pdf
4 条回复
•
2016-04-26 08:44:17 +08:00
1
askask
OP
2016-04-19 17:13:29 +08:00
http://qa.helplib.com/471954
找到一篇文章 看不太名单 myview 和模板是怎么搭配的
2
yybeta
2016-04-19 17:25:59 +08:00
用 pdfcrowd 实现过,感觉比 xhtml2pdf 排版等问题要少得多,
http://pdfcrowd.com/
很容易实现,唯一的坏处是免费配额只有 100 次好像。
3
askask
OP
2016-04-19 17:42:48 +08:00
@
yybeta
问题是要钱哟~
4
askask
OP
2016-04-26 08:44:17 +08:00
已解决。
直接采用 python-pdfkit ,亲测好用。
分享下链接:
https://github.com/JazzCore/python-pdfkit
直接按照说明安装即可。
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
5262 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms ·
UTC 08:19
·
PVG 16:19
·
LAX 01:19
·
JFK 04:19
Developed with
CodeLauncher
♥ Do have faith in what you're doing.