mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.53k stars 645 forks source link

wicked_pdf https image url not rendering in pdf file #848

Open prashant-maropost opened 5 years ago

prashant-maropost commented 5 years ago

Issue description

I am rendering dynamic HTML content in pdf file using wicked pdf gem. The problem I am facing is the image is not rendering into generated pdf. source URL is forcefully redirected to HTTPS instead of HTTP. Is there any way out to render the https link from wicked pdf gem

I had tried to hit image URL manually on the browser is forcefully redirected to HTTPS instead of HTTP http://designmodo.com/demo/emailtemplate/images/header-background.jpg

Expected or desired behavior

the give image URL should be rendered in pdf created

System specifications

Linux centos 6.7, ruby version 2.3.6, wicked_pdf (1.1.0)

unixmonkey commented 4 years ago

If there's a resource you can't render from an html file, you could always try retrieving it beforehand and embedding it with something like what is shown in this comment: https://github.com/mileszs/wicked_pdf/issues/36#issuecomment-91027880

goodanthony commented 4 years ago

@prashant-maropost, bellow works <%= wicked_pdf_image_tag( request.ssl? ? photo["first_resize"] : photo["first_resize"].gsub("https://", "http://")) %>

unixmonkey commented 4 years ago

@iamfree-com The original poster said that his image is forcefully redirected to HTTPS when you request over HTTP, so while your solution may work for you, it won't in this case.

@prashant-maropost I believe the issue you are describing can be solved by installing one of the more recent versions of wkhtmltopdf.

There were some versions of wkhtmltopdf (in the earlier 12.x version range) that used SSLv3 for HTTPS. Many hosts disabled SSLv3 at the router layer to prevent Heartbleed attacks, so many (but not all) HTTPs requests just kind of stopped working when they did that.

I recommend updating to the newest wkhtmltopdf version and seeing if that solves your issue. If your CentOS package repository doesn't have one new enough, try the wkhtmltopdf-binary gem.