I am getting an error(Blocked access to the file) in HTML to pdf conversion using pdfkit library while using a local image in my HTML file. How can I use local images in my HTML file?
pdfkit- Warning: Blocked access to file
I faced the same problem. I solved it by adding "enable-local-file-access" option to pdfkit.from_file().
options = {
"enable-local-file-access": None
}
pdfkit.from_file(html_file_name, pdf_file_name, options=options)
Using wkhtmltopdf 0.12.6 and pdfkit 0.6.1, this option for me, while kimbespo's did not. –
Bolger
Pdfkit is a python wrapper for wkhtmltopdf. It seems to have inherited the default behaviour of wkhtmltopdf in recent versions, which now blocks local file access unless otherwise specified.
However, since pdfkit allows you to specify any of the original wkhtmltopdf options, you should be able to resolve this problem by passing the enable-local-file-access
option.
Following the example on the pdfkit site, that would probably look something like this:
options = {
"enable-local-file-access": ""
}
pdfkit.from_string(html, output_path=False, options=options)
© 2022 - 2024 — McMap. All rights reserved.