Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues rending images from HTTPS #344

Open
jmesserer opened this issue Oct 16, 2014 · 58 comments
Open

Issues rending images from HTTPS #344

jmesserer opened this issue Oct 16, 2014 · 58 comments

Comments

@jmesserer
Copy link

Hi All,

A couple days ago I realized that images were missing from the PDF's I'm generating ... it wasn't an issue prior to that and I'm still trying to track down what "changed" (no code changes on my end). Anyways ... I noticed that images sourced from HTTPS are not rendering in the generated PDF's but they do render when show_as_html is enabled.

Anybody have any insight into this issue?

I've setup a working example of the issue @ http://dev.e-snapapps.com/welcome/test.pdf (for show_as_html use http://dev.e-snapapps.com/welcome/test.pdf?debug=true).

Thanks =~ J

@prochazkajp
Copy link

Hi, I have the same problem. It was working perfectly in the past and now just blank squares in the pdf.. Although when you use <%= wicked_pdf_image_tag 'image' %> helper, it works fine as well as using just links with http.

@jmesserer
Copy link
Author

I've tried using wicked_pdf_image_tag but it appears that that helper ONLY works for local resources. This isn't the issue at hand but just wanted to be thorough.

When I try to use it to render a remote image using wicked_pdf_image_tag (either HTTP or HTTPS) it fails with the following error.

F, [2014-10-17T11:00:58.321786 #7285] FATAL -- :                                                                                                                                                               
ActionView::Template::Error (undefined method `pathname' for nil:NilClass):                                                                                                              
    11:                 <%= wicked_pdf_image_tag 'http://rubyonrails.org/images/rails.png' %>
    12:         </body>                                                                                                                                                                                        
    13: </html>                                                                                                                                                                                                
  app/views/welcome/test.pdf.erb:11:in `_app_views_welcome_test_pdf_erb__928987179_86697920'                                                                                                                   
  app/controllers/welcome_controller.rb:12:in `block (2 levels) in test'                                                                                                                                       
  app/controllers/welcome_controller.rb:9:in `test'        

@unixmonkey
Copy link
Collaborator

@jmesserer Remote images that aren't part of the asset pipeline or in /public can just use regular image_tag.

@jmesserer
Copy link
Author

@unixmonkey - Thanks ... I was aware of that but I'm still seeing an issue with remote images sourced from HTTPS locations as seen in my example @ http://dev.e-snapapps.com/welcome/test.pdf

Doesn't work -->
<%= image_tag 'https://www.etsy.com/assets/dist/images/etsylogo.0000.png' %>

Works -->
<%= image_tag 'http://rubyonrails.org/images/rails.png' %>

Thanks =~ J

@danmelnick
Copy link

Also seeing this issue — is there anything I can do to get more verbose debug output to help narrow down the cause?

@mrsweaters
Copy link

I am also experiencing this issue. Local images render just fine, but remote images (S3, Rackspace Cloudfiles) served over SSL fail to render.

@dominicgoulet
Copy link

I'm also experiencing this issue. Any ideas? It really has to do with HTTPS.

This one works : http://www.etsy.com/assets/dist/images/etsylogo.0000.png
While this one does not : https://www.etsy.com/assets/dist/images/etsylogo.0000.png

@jmesserer
Copy link
Author

I haven't figured anything out yet but in the meantime I was able to circumvent the issue by downloading the images I need (using httparty gem) and rendering them locally. I'm sure there's room for improvement but it works and gets my users up & running again.

# download image
remote_image = 'https://www.google.com/images/srpr/logo11w.png'
local_image = "#{Rails.root}/public/images/#{File.basename remote_image}"

unless File.exists? local_image
  File.open(local_image, 'wb') do |f| 
    f.write HTTParty.get(remote_image).parsed_response
  end       
end

# render in PDF
<% local_image = File.basename remote_image %>
<%= wicked_pdf_image_tag(image_path(local_image)) %>

@unixmonkey
Copy link
Collaborator

It appears that the server will need openssl-devel packages installed for this to work, even with a statically compiled binary.

See https://code.google.com/p/wkhtmltopdf/issues/detail?id=17

@dominicgoulet
Copy link

Any clue how to fix this on Heroku?

@jeroenj
Copy link

jeroenj commented Oct 23, 2014

We've encountered the same issue. Since last week assets fetched over HTTPS were no longer working. As it turns out the latest stable relase of wkhtmltopdf uses SSLv3 for its HTTPS connections.
Since the SSLv3 POODLE attack a lot of web hosts have disabled SSLv3.
The best solution right now is to install the wkhtmltopdf v1.2.2 testing release.

@jeroenj
Copy link

jeroenj commented Oct 23, 2014

I've also created an issue in the wkthmltopdf binary gem project. Once there is a (pre-)release of the gem it should be possible to use it on heroku too.

@unixmonkey
Copy link
Collaborator

@joelcogen Thanks for pointing out that this is related to Heroku and others disabling SSLv3. I was wondering how so many people were just now starting to have issues when things have been working so well for years.

@dalibor
Copy link

dalibor commented Oct 25, 2014

The issue with missing images (on sites that disable SSLv3) seems fixed if you use wkhtmltopdf-binary binaries from the master branch. Hopefully, we'll see a release soon: zakird/wkhtmltopdf_binary_gem#17.

@nfriend21
Copy link

Im having this issue too. No solution yet.

@jensbjork
Copy link

+1

@akash209
Copy link

This is weird. if i set direct path of image it shows image but when i use dynamic data to show path it dosent work. here is an example.
<% barcode_name = "barcode_"+@my_ticket[:barcode_random]+'_'+@my_ticket[:id].to_s+'.png' %>
<% full_br_path = 'http://abc.com/eventdemo/public/data/barcode/'+barcode_name %>

This doesn't work but when i write below code it works.

how do i get dynamic data for img tag, i'm getting dynamic data for other parts like ticket price ,name and order number.
** note **
I have change img to imgs becase i don't know how to use code formatting here and that img tags are showing broken image because of fake domain name.

@lucascaton
Copy link

Hi @mileszs!
Any news on this issue?
Thanks.

@holden
Copy link

holden commented Jan 15, 2015

I had this same issue on Heroku serving images from CloudFlare.

We'd been serving them successfully using CloudFare Pro but when we downgraded to the Free version the images stopped working when using SSL. (Seems the Pro vs Free version has some difference regarding SSL).

Upgrading to the latest WKTHMLtoPDF version seemed to fix it using:

https://github.com/dscout/wkhtmltopdf-buildpack

@jfrux
Copy link

jfrux commented Apr 15, 2015

I'm using wkhtmltopdf 0.9.9 in local dev and production. Latest version of wkhtmltopdf loads really slow on OS X for some reason so I've chosen not to go above 0.9.9. Guess I'm going to have to use local http:// for my images. Thanks for the update.

@jimthedev
Copy link

Hi all,

I had this issue on version: 0.12.1 (with patched qt).

I was able to resolve it by upgrading to version: 0.12.2.1 (with patched qt)

@ryanwjackson
Copy link

Has anyone found a solution to this other than copying images to a non-https location? I've tried using the wkhtmltopdf-binary gem, but it has no effect.

Strangely this only stopped working recently, as it has been working for the past few months. I don't check the PDFs every day, but we just started noticing them not having images. We are using S3, and I suspect it's something along the lines of what @jeroenj was saying regard SSL.

Is there a way to using the testing version of wkhtmltopdf with wicked_pdf, specifically on Heroku? Or is there another solution?

@nfriend21
Copy link

Yes, all I did was a gsub on the image tags and it worked perfectly, as follows:

<%= image_tag(image_url.gsub('https', 'http') %>

@unixmonkey
Copy link
Collaborator

@ryanwjackson Yes, you can install the newest wkhtmltopdf and copy it to your bin directory in Rails, and point :exe_path at it in config/initializers/wicked_pdf.rb, or use https://github.com/rposborne/wkhtmltopdf-heroku

@ryanwjackson
Copy link

I ended up going with installing wkhtmltopdf directly on my computer and then using the suggestion above of a buildpack: https://github.com/paidapi/wkhtmltopdf-buildpack.

And it's notable that @nfriend21's solution did work, but I see that as a bandaid rather than a fix. Hopefully someone will update the binary gem and all will be right in the world.

@DaveCollinsJr
Copy link

FYI That Amazon discontinued support for SSLv3 in S3 on May 20th 2015. Just around that time we started having this problem with images no longer appearing in our pdf output.

@avalente1
Copy link

Yes, the last AWS extension was until June 8 2015 and then we faced this issue as well...

<%= image_tag image_url.gsub('https', 'http') %> worked after many failed attempts at fixing the issue other ways.

@garside
Copy link

garside commented Jun 17, 2015

To add a bit of insight, I found out today that the underlying gem, wkhtmltopdf is what handles the pulling in of images from s3.

Using rails on heroku, we were able to simply switch over gem 'wkhtmltopdf-binary, which is just out of date and uses the old (now deprecated as of June 8) SSLv3 module.

The new gem, -edge with a different maintainer seems to fix the issue!

gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'

Though beware, we did have some minor styling issues that needed correction with some html5 elements, such as an unwanted border around <header> tags. Dunno what else.

@jimthedev
Copy link

It seems like the bottom line is that if you’re experiencing this issue then you probably have some dependency in the pipeline that is not updated to the most recent version.

On Wed, Jun 17, 2015 at 1:45 PM, Eric Garside notifications@github.com
wrote:

To add a bit of insight, I found out today that the underlying gem, wkhtmltopdf is what handles the pulling in of images from s3.
Using rails on heroku, we were able to simply switch over gem 'wkhtmltopdf-binary, which is just out of date and uses the old (now deprecated as of June 8) SSLv3 module.
The new gem, -edge with a different maintainer seems to fix the issue!
gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'

Though beware, we did have some minor styling issues that needed correction with some html5 elements, such as an unwanted border around <header> tags. Dunno what else.

Reply to this email directly or view it on GitHub:
#344 (comment)

@bcackerman
Copy link

@garside solved the issue for me. Just make sure, like he said, to check formatting again. Some things shifted.

@garside
Copy link

garside commented Jul 15, 2015

Also, just a note to @lalitlogical, @bcackerman, and @Epigene:

If you guys are on heroku, there's a heroku specific gem that works and is "more reliable" than the -binary-edge gem. There was some notice that you shouldn't "use it in production" (though we had it there for a bit and it wasn't an issue, but we have an offline generator for pdfs).

In our gemfile we have:

group :development, :test do
  gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'
group :staging, :production do
  gem 'wkhtmltopdf-heroku'

@lanxichan
Copy link

Thanks @garside
I have do a lot of research to try to fix this problem, I use the 'wkhtmltopdf-binary-edge' and now it is working fine.
And @nfriend21 , your method is also very smart😄

@tgoldenberg
Copy link

+1 @garside

@jwoertink
Copy link

I'm having issues getting my images to render too. I have a logo in my app/assets/images/logo.png as well as public/images/logo.png. I'm using wicked_pdf_image_tag('logo.png', size: '240x66'), and I'm on a SSL domain. When I generate a pdf, it just says "Logo", but doesn't actually render the image in production. In development it works just fine.

@unixmonkey
Copy link
Collaborator

@jwoertink What version of wkhtmltopdf are you using?

Does it work with the wkhtmltopdf-binary-edge gem?

@jwoertink
Copy link

I'm using

gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'
gem 'wicked_pdf'

@unixmonkey
Copy link
Collaborator

@jwoertink

Does it work without the size option?

Try adding the option debug: true to your render, then right-clicking and viewing the source, to see if it looks like it's doing the right thing. It should be a <img src="file:///... with a complete path to the asset.

If that doesn't help you track down the issue, I might suggest you embed a base64 encoded image as demonstrated in #257

@jwoertink
Copy link

Ok, so I changed it up a bit. I did image_tag("file://#{Rails.root.join('public', 'images', 'logo-full.png')}"), and it works. When I add the size option back in, I got this error.

PDF could not be generated! Command Error: /srv/namechk/shared/bundle/ruby/2.1.0/gems/wkhtmltopdf-binary-edge-0.12.2.1/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory 

@unixmonkey
Copy link
Collaborator

@jwoertink Ah, that helps.

The wkhtmltopdf-binary-edge gem is statically compiled, but still has some dynamic dependencies.

If you can control the server, try this: http://stackoverflow.com/a/5036301/23915

Otherwise, I'd either try an older version of the wkhtmltopdf-binary gem, or compile your own binary.

@jwoertink
Copy link

oh nice! Yup, that worked! Thanks so much.

@alex-gutierrez
Copy link

+1 @garside 👍

@leaniman
Copy link

@garside 👍

@quintorp
Copy link

@garside 👍

@alkami-io
Copy link

If it wasn't mentioned before... if you were using 'wkhtmltopdf-binary' and are switching to 'wkthmltopdf-binary-edge' it seems you need to uninstall 'wkhtmltopdf-binary' removing it and rebundling didn't work for me but it did work once I ran gem uninstall 'wkhtmltopdf-binary'

@skyach-001
Copy link

I am having an issue that I hope you may have knowledge about.The images were missing from the PDF's I'm generating(wicked_pdf). There is an issue with HTTPS request for wicked PDF, when i replace HTTPS with HTTP it worked but i have so many PDFs and don't want to change HTTPS to HTTP. I tried updating gem to this (gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1') but this too did not work for me. I am wandering here and there for the reason why this is happening.
I have following configurations.
Configuration of nginx(1.14) and OpenSSL 1.1.0g 2 Nov 2017 with ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
Please help me to sort out this issue, If possible please elaborate the reason too.

@unixmonkey
Copy link
Collaborator

@skyach-001 Please update to the latest gem 'wkhtmltopdf-binary-edge', '~> 0.12.5.0' and report back.

@skyach-001
Copy link

Hello @unixmonkey , as per suggested i update the gem but still got error "Error message
RuntimeError: PDF could not be generated! Command Error: */vendor/bundle/ruby/2.1.0/gems/wkhtmltopdf-binary-edge-0.12.5.0/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory" will you please help me to figure out the problem.

@unixmonkey
Copy link
Collaborator

@skyach-001 I suggest you post this here, but it looks like your system needs libpng and likely some other libraries installed for wkhtmltopdf to work properly.

Make sure to provide some info about your operating system and platform.

@guyzmo
Copy link

guyzmo commented Sep 17, 2019

As a solution, I used the system's packaged wkhtmltopdf in the containers, and it works fine. Only drawback : it downloads a hell lot of dependencies.

@McGeekiest
Copy link

Version 0.12.5.0 appears to be incompatible with the Heroku-18 stack. The only way I could get it to work on Heroku was to load S3 images over http rather than https.

This is a better substitution than the ones that have been mentioned above — it's nil-safe and anchored to the start of the string:

image_url&.gsub(/^https/, 'http')

@unixmonkey
Copy link
Collaborator

@McGeekiest This solution should not have anything to do with the Heroku 18 stack, but loading HTTPS resources over many networks (including AWS). The workaround of loading assets over HTTP isn't always available (like for domains that force SSL), so you may need to do something like request the content with open-uri, read it in and output a local file or a base64 representation inline.

@McGeekiest
Copy link

@unixmonkey Understood, but I was responding to "Please update to the latest gem 'wkhtmltopdf-binary-edge', '~> 0.12.5.0' and report back." That is not an option on Heroku-18, at least out-of-the-box, due to a libjpeg incompatibility.

Also, certainly, this does not present a general solution for all HTTPS resources, but for the specific combination of Heroku and AWS the gsub solution resolves the issue.

@unixmonkey
Copy link
Collaborator

@McGeekiest Gotcha. Thanks for clarifying.

It appears that the latest https://github.com/rposborne/wkhtmltopdf-heroku works on Heroku-18 based on this

@Vinay-Gurjar
Copy link

i my case when i change image extension .svg to .png its my image downloaded successful in my pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests