Image file can't covert to pdf when using python-pdfkit

1.5k views Asked by At

Here is my code

options = {
      "enable-local-file-access": True,
      ...
}
pdfkit.from_string(html_file, pdf_file, options=options, ...)

since Im using Django template, here is my code to reference that

 <img src="{{ static_root }}{% static '../../target.svg' %}" alt="">

I use a local image file in html, It just shows a blank box in pdf output file

I also tried using "base64" to resolve my issue base on this link pdfkit not converting image to pdf

It doesn't really work to me.

2

There are 2 answers

0
Dan On

realized pdfkit doesn't like .svg, I use .png format instead

0
user2120353 On

wkhtmltopdf 0.12.6 (Ubuntu 22.04.1 LTS) (console) - all ok

wkhtmltopdf --enable-local-file-access ./file.html ./file.pdf

in python script not so bad too:)

options = {'enable-local-file-access': None}

pdfkit.from_file("file.html", "file.pdf", options=options) # all ok!

pdfkit.from_string(html_str,  "file.pdf", options=options) # no images (jpg, png) :(