0

I would like to convert html to pdf using pdfkit, but when i try to run in lambda i got the errors

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: ''

My code:

import pdfkit
pdfkit.from_string(html_content, "testing.pdf")

the code is runing in my local py file, but not working in aws lambda. Any idea to solve this issue? or any other lib suggestions???

Thank You

TSW
  • 41
  • 7
  • 1
    Please read https://docs.aws.amazon.com/lambda/latest/dg/python-package.html and ensure that you have packaged the depend library with code or making it available through Lambda layer so the python runtime for lambda can make it available. – karan shah Nov 16 '21 at 12:25

1 Answers1

3

You need a add wkhtmltopdf layer to your lambda function. You can get it from here https://wkhtmltopdf.org/downloads.html#stable And in your python code add the config to pdfkit like below

PATH_WKHTMLTOPDF = '/opt/bin/wkhtmltopdf'
PDFKIT_CONFIG = pdfkit.configuration(wkhtmltopdf=PATH_WKHTMLTOPDF)
pdfkit.from_string('somehtml',configuration=PDFKIT_CONFIG)
Azhar Syed
  • 619
  • 1
  • 7
  • 14