1. 程式人生 > >python生成pdf

python生成pdf

 

程式碼

需要先安裝wkhtmltopdf,下載路徑https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.mxe-cross-win64.7z,需FQ 

import sys
reload(sys)
sys.setdefaultencoding('utf8')
import pdfkit
path_wk = r'E:\wkhtmltox\bin\wkhtmltopdf.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)

 

 

輸入檔案如下

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