pdfkit image not embedded using Django

Question:

I’m converting a protected webpage into pdf using Django and this solution.

The solution works great except the part that the webpage contains images which do not show up in the pdf and i get an error

Warning: Failed to load file:///media/images/main/logo.jpg (ignore)

I’m currently using from_string method as follows

pdfkit.from_string(msg_html, 'testing123.pdf') #msg_html contains html string with images
Asked By: Irfan Harun

||

Answers:

turns out that url of images in html document that needs to be converted to pdf using pdfkit needs to have an absolute url

in my html file, i had to update my urls as follows:

<img src="/media/images/main/logo.jpg">

to

<img src="https://test.mywebsite.com/media/images/main/logo.jpg">

using this i was able to generated pdf containing my logo from the html file

Answered By: Irfan Harun
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.