Chow's Notes

Python中将html转换成pdf的方法

1.使用在线的接口,但是基本要收费和限制调用次数

例如:pdfcrowd

接口地址:https://pdfcrowd.com/html-to-pdf-api/

2.xhtml2pdf

源码地址 :https://github.com/xhtml2pdf/xhtml2pdf

1
2
3
4
5
6
7
8
9
import xhtml2pdf.pisa as pisa
dest='test.pdf'
f=open('shiptemp_1.html')
data=f.read()
print data
pdf = pisa.CreatePDF(
data,
file(dest, "wb")
)

3.Python-PDFKit: HTML to PDF wrapper

https://github.com/JazzCore/python-pdfkit

依赖的环境,安装稍微复杂,但功能强大