wkhtmltopdf not working after deploying in Azure function

Viewed 116

I have an azure function that convert html file to pdf using the module pdfkit python.

Here is the shell script of deployment where I install wkhtmltopdf and it is successfull. The dependancy is installed in the location 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

Here is my azure function code which generate 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)

After deploying the function, When tested, it showing following error

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

What I am missing here? Thank you

1 Answers

When you deployed the platform took all your code but didn't took the executable with it that's why it is giving the error you need to add the executable inside the azure function root directory then install it.

Then I would suggest, to containerize the entire function and then deploy it in azure.

Refer the following documentation on how to deploy azure function using docker.

Refer the following article by Gabriel Cufaro.

Related