pdfkit- Warning: Blocked access to file
Asked Answered
C

2

12

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?

Covariance answered 9/7, 2020 at 12:16 Comment(0)
S
38

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)
Spina answered 20/8, 2020 at 10:28 Comment(1)
Using wkhtmltopdf 0.12.6 and pdfkit 0.6.1, this option for me, while kimbespo's did not.Bolger
P
4

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)
Procopius answered 27/7, 2020 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.