且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用 python PDFKIT 创建 pdf 错误:"未找到 wkhtmltopdf 可执行文件:"

更新时间:2023-02-16 12:52:14

以下应该可以工作而无需修改 windows 环境变量:

The following should work without needing to modify the windows environment variables:

import pdfkit
path_wkhtmltopdf = r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("http://google.com", "out.pdf", configuration=config)

当然假设路径是正确的(例如,在我的情况下,它是 r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').

Assuming the path is correct of course (e.g. in my case it is r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').