python - 在 Azure 功能中部署后 wkhtmltopdf 无法正常工作

标签 python shell ubuntu azure-functions

我有一个使用模块 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/

相关文章:

python - 放大数据、重新调整 y 轴刻度的最有效方法

linux - 使用 Linux (Debian) 获取图像中像素的颜色

exception - 导入错误 : No module named exceptions

shell - 检查参数数量是否正确

linux - Linux中模式匹配后提取内容

linux - 关闭所有正在运行的虚拟机并再次启动自动启动机器

java - 运行已编译的java程序的问题

python - 是否可以从 SQL Server 在 Active Directory 中启动新条目或更新 Active Directory 中的现有条目?

python - Django 表单在提交之前正在验证

python - 无法在 Jupyter notebook 中导入 opencv 但能够在 Anaconda 的命令行中导入