11

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?

sanjay
  • 514
  • 2
  • 5
  • 14

2 Answers2

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