python生成pdf

 代码

需要先安装wkhtmltopdf,下载路径https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.mxe-cross-win64.7z,需翻墙 

import sys
reload(sys)
sys.setdefaultencoding('utf8')
import pdfkit
path_wk = r'E:wkhtmltoxinwkhtmltopdf.exe' #安装位置
config = pdfkit.configuration(wkhtmltopdf = path_wk)
pdfkit.from_url('https://www.cnblogs.com/', 'out1.pdf', configuration=config)
# pdfkit.from_string('Hello!', 'out3.pdf', configuration=config)

pdfkit显示的是html对应的内容,js生成的内容显示不出来

pdfkit.from_string可以直接写html对应的字符串,样式也会生效 

输入文件如下

https://files.cnblogs.com/files/lurenjia1994/out1.pdf

原文地址:https://www.cnblogs.com/lurenjia1994/p/9957215.html