我希望使用pdfkit将html转换为pdf,但是当我尝试在lambda中运行时,我得到了错误。
No wkhtmltopdf executable found: ""
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/pdfkit/configuration.py", line 35, in __init__
with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: ''我的代码:
import pdfkit
pdfkit.from_string(html_content, "testing.pdf")代码在我的本地py文件中运行,但在aws中不工作。有什么办法解决这个问题吗?或者其他随意的建议?
谢谢
发布于 2022-03-18 20:14:11
您需要向lambda函数添加wkhtmltopdf层。您可以从这里获得它,https://wkhtmltopdf.org/downloads.html#stable,在您的python代码中,将配置添加到pdfkit,如下所示
PATH_WKHTMLTOPDF = '/opt/bin/wkhtmltopdf'
PDFKIT_CONFIG = pdfkit.configuration(wkhtmltopdf=PATH_WKHTMLTOPDF)
pdfkit.from_string('somehtml',configuration=PDFKIT_CONFIG)https://stackoverflow.com/questions/69983439
复制相似问题