I'm having an issue very similar to this post: pdfkit - python : 'str' object has no attribute decode
I'm running a python script via a web app.
import pdfkit after installing it with pip3, python version 3.6.
import pdfkit
def pdfkit(source, method):
if method == "string":
try:
options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
}
config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf", 'utf8'))
pdf = pdfkit.from_string(source, False,options=options,configuration=config)
return pdf
except Exception as e:
return str(e)
else:
return "Error: Not yet Supported"
I installed wkhtmltopdf following these instructions for UBUNTU 20.04. It says that these are "headless" and can be executed from the command line. In fact, it does when using the pdfkit wrapper, but when I try to run via the python script itself it doesn't work.
One of the errors that I am getting is:
{
"pdf": "'function' object has no attribute 'configuration'"
}
among other, like the same for from_string if I remove the configuration.
Just wondering if I need to import some other modules or if I need a different version of wkhtmltopdf on the system.
Do I need to get a different binary, or follow the directions here. It is confusing because there are multiple ways to install that, the CLI, the .deb package and using the info on GitHub. Thanks.