skip to Main Content

I am using an azure function to create pdf of html data sent to an azure storage account queue, while the entire solution works on my device, I had assumed that I can substitute the need of pdfkit’s wkhtmltopdf dependency with a package such as https://pypi.org/project/py3-wkhtmltopdf/ which basically clones the files of python3-wkhtmltopdf.

As of now, I am stuck at installing the wkhtmltopdf package in a way such that pdfkit works without needing to go for containerization of the code. (https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-custom-container?tabs=core-tools%2Cacr%2Cazure-cli&pivots=azure-functions) It will increase the development time substantially.

If anyone has managed to use pdfkit or any other alternative without the need of installing binaries, or if you have successfully installed wkhtmltopdf such that it works with pdfkit without using binaries please share how you did it.

2

Answers


  1. Chosen as BEST ANSWER

    The Azure Functions architecture is tricky and based on various answers using python's os package, I found a way to understand the version of the Debian os and de-packaged / unpacked the .deb file for the latest wkhtmltox (which was still outdated in comparison to the version) but this time around the backward compatibility actually kicked in.

    PS. I know this is not the ideal solution and I am looking into other libraries that are still active, containerization as pointed out above and more. This is a solution that worked for me but for anyone reading this in the future, please opt for containerization from the start! or use another package to avoid heavy development costs like I had to.


  2. If anyone has managed to use pdfkit or any other alternative without the need of installing binaries

    AFAIK, the wkhtmltopdf need binary file. Yes you need to containerize code as it needs the binary file.
    While doing in local i use below code :

    import subprocess
    import azure.functions as func
    
    def main(req: func.HttpRequest) -> func.HttpResponse:
        rith_text = req.get_body().decode('utf-8')
        inputfilpath =r'c:UsersjaDownloads78078887.html'
        outfile = r'c:UsersjaDownloads'
        with open(inputfilpath, 'w', encoding='utf-8') as i:
            i.write(rith_text)
        subprocess.run(['c:Program Fileswkhtmltopdfbinwkhtmltopdf.exe', inputfilpath, outfile])
        with open(outfile, 'rb') as pdfile:
            rescon = pdfile.read()
        return func.HttpResponse(rescon, mimetype='application/pdf', status_code=200)
    

    enter image description here

    I do agree with @K J, text conversion is easy but not with png/jpeg.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search