Nagabhushan S N
Nagabhushan S N

Reputation: 7277

pdfkit not getting embedded images in a webpage

I'm trying to save a webpage as pdf using pdfkit. However, in the saved PDF, there are no images. They all have a question mark icon in place of images. Why is this happening? Is it possible to fix this?

For example, as below:

import pdfkit

pdfkit.from_url('https://www.quora.com/Spoilers-What-is-something-you-noticed-in-Avengers-Endgame-that-you-believe-others-have-missed/answer/Prabhhav-Sharma?ch=3&share=5feaef03&srid=aHe5', 'output.pdf')

I'm getting the below warning. May be this is the issue.

libpng warning: iCCP: known incorrect sRGB profile

The solutions I found on web are to modify the png file, which I can't do here since pdfkit is loading the image from the webpage. Is there a way to solve this?

PS: I'm open to using any other utilities to save PDF from webpage URL. Also, this is for my personal use.

Upvotes: 3

Views: 1193

Answers (1)

Nagabhushan S N
Nagabhushan S N

Reputation: 7277

The problem is not with incorrect sRGB profile. It's just that the site is not given enough time to load the images. This problem can be fixed by increasing the javascript-delay in the options passed to pdfkit.from_url

pdfkit_options = {
    'javascript-delay': '10000',  # Increase this value if images are not loading properly
}
pdfkit.from_url(url, output_path, options=pdfkit_options)

Upvotes: 1

Related Questions