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?
Asked
Active
Viewed 1.0k times
2 Answers
37
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)

Susumu Ishihara
- 386
- 2
- 3
-
Using wkhtmltopdf 0.12.6 and pdfkit 0.6.1, this option for me, while kimbespo's did not. – GoblinTheodicy Sep 11 '20 at 16:24
3
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)

modsquadron
- 594
- 5
- 9

kimbespo
- 131
- 2