我有一个使用模块 pdfkit python 将 html 文件转换为 pdf 的天蓝色函数。
这是我安装 wkhtmltopdf 的部署 shell 脚本,它是成功的。依赖安装在位置 usr/local/bin/wkhtmltopdf
echo "Starting Installation of wkhtlmtopdf for disclosure document generation..."
export DEBIAN_FRONTEND=noninteractive
apt update
apt install wget
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb -y
chmod -R a+rwx /usr/local/bin/wkhtmltopdf
这是我生成pdf的天蓝色函数代码options = {
'enable-local-file-access': None,
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header': [
('Accept-Encoding', 'gzip')
],
'no-outline': None
}
config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
pdfkit.from_file('index.html',
'output.pdf',
options=options,
configuration=config)
部署该功能后,测试时显示以下错误No wkhtmltopdf executable found: "/usr/local/bin/wkhtmltopdf" 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
我在这里缺少什么?谢谢
最佳答案
当您部署平台时,您使用了所有代码,但没有使用可执行文件,这就是为什么它会给出错误,您需要在 azure 函数根目录中添加可执行文件,然后安装它。
然后我建议,将整个功能容器化,然后将其部署在 azure 中。
引用以下documentation关于如何使用 docker 部署 azure 功能。
引用以下article加布里埃尔·库法罗。
关于python - 在 Azure 功能中部署后 wkhtmltopdf 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72332464/