wicked_pdf
wicked_pdf copied to clipboard
A pdf with an external image doesn't get rendered
While this is rendered properly:
<img src="<%= File.join($config[:wicked_pdf_static_assets_physical_file_root], '/images/sample.png' ) %>" />
this doesn't, as if an image didn't exist:
<img src="https://some_url_here/image.png" %>" />
Is this an intended behaviour? What's the workaround? An image exists
The syntax you posted above includes and unbalanced closing paren and erb tag, but that was probably a typo, so I'll assume you are having an issue with a normal image tag like this:
<img src="https://some_url_here/image.png" />
If you render with render pdf: 'mypdf', show_as_html: true
, do you still have issues?
Open the inspector console and look for warnings.
It is a specific HTTPS image, or several?
My thoughts are perhaps there may be server-side referrer checking that prevents hot-linking of images from other domains, some kind of cross-site request forgery, or maybe an untrusted or invalid SSL certificate.
There were some versions of wkhtmltopdf (in the earlier 12.x version range) that used SSLv3 for HTTPS. Many hosts (including Heroku) disabled SSLv3 to prevent Heartbleed attacks, so things just kind of stopped working when they did that. Newer versions of wkhtmltopdf have addressed the issue.
I recommend updating to the newest wkhtmltopdf version if you suspect this is the issue, but if you have installed a version from the past few years, I suspect this isn't your issue.
Let me know how it goes!
Yes, that was a typo. It's a rack app, non-rails.
Is render pdf: 'mypdf', show_as_html: true
a fucntion of the gem? Or Rails?
I'm using AWS S3 for storing an image. I can access it directly via a browser, in the incognito mode too.
gemfile.lock:
wkhtmltopdf-binary (0.12.3.1)
pdf-core (0.7.0)
pdfkit (0.8.2)
wicked_pdf (1.1.0)
They are functions of the gem, but hook into Rails’ rendering engine. I assume then that you are using WickedPdf.new.render_from_string(html, options)
then? Can you share some info about how you are using it and perhaps an image link that you are having trouble with?
Will do later An image is accessiable from wget too
I've included 2 public images and they're still not getting rendered:
<br />
<br />
<br />
<img src="https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg" />
<br />
<br />
<br />
<img src="http://via.placeholder.com/350x150" />
I generated an html file out of my html code and the images were shown correctly.
In a pdf they're rendered as lines, 2 ones in this case
I'm creating a pdf this way:
fl = WickedPdf.new.pdf_from_string(html)
fl_nm = "/tmp/123.pdf"
File.open(fl_nm, "wb") {|x| x << fl}
when an image is located locally, it's working
We had the same issue. We haven't tracked down yet what settings are causing this, but changing the link to http (as mentioned in this SO answer) allowed the images to render properly.
Same issue, and thankfully the SO answer linked above works (thanks @EmilyMB!). This might not be relevant to this issue since the author used
<img src="http://via.placeholder.com/350x150" />
but it's probably good to know regardless for those who wander here.
Same problem
Same problem
Still not fixed?(
@abdullaachilov Are you using a binary gem, or your system packages?
Is your wkhtmltopdf
binary compiled with SSL support?
Does your hosting system need the ssl dev libraries installed?
Are the image links fully-qualified with protocol and host (not relative)
Does the server you are loading images from allow them to be rendered from a 3rd-party site (which is what rendering from a local tempfile is doing)?
If you put a binding.pry here in wicked_pdf.rb#pdf_from_string, or here in wicked_pdf.rb#pdf_from_url, and either make a copy of the tempfile from your filesystem, or copy the contents of the string to an html file, does it work when you open that local file with Chrome?
Quick response, cool, I will gather all info now, as Im dealing with that trouble for some time already. @unixmonkey
Does your hosting system need the ssl dev libraries installed?
- We using our own server on ubuntu 18.04. our website works via https (nginx)
Are you using a binary gem, or your system packages?
- I think I remember I've installed it from binary, how can I check it?
Is your wkhtmltopdf binary compiled with SSL support?
- How I can check it?
Does the server you are loading images from allow them to be rendered from a 3rd-party site (which is what rendering from a local tempfile is doing)?
- Yes, it is from Cloudinary. We use same images just on website.
If you put a binding.pry here in wicked_pdf.rb#pdf_from_string, or here in wicked_pdf.rb#pdf_from_url, and either make a copy of the tempfile from your filesystem, or copy the contents of the string to an html file, does it work when you open that local file with Chrome?
- same links on localhosts works perfectly fine (MacOS) problem on both servers (ubuntu 18.04 each)
We using our own server on ubuntu 18.04. our website works via https (nginx)
That doesn't answer the question. Please visit the link I posted about installing SSL libraries in your staging or production environment and retry your PDFs.
I think I remember I've installed it from binary, how can I check it?
cat Gemfile.lock | grep wkhtmltopdf
will tell if you are using a wkthmltopdf
binary gem.
If that does not have anything, then on your Ubuntu servers, apt list --installed | grep wkhtmlto
should tell you if you installed a system package (that may not be compiled with SSL or QT feature support to make more than basic uses work)
Yes, it is from Cloudinary. We use same images just on website.
But are they full "https://example.com/path/to/image.jpg" src's on the image tags, or are they relative like /path/to/image.jpg
? When rendered from a tempfile, they need to be fully qualified, and include the protocol and host.
same links on localhosts works perfectly fine (MacOS) problem on both servers (ubuntu 18.04 each)
Yes, but on localhost, your images are served in development mode, which usually means relative paths. Please try what I suggested. I think it will help you determine why the images might not be showing if you open the tempfiles, and the images don't show up there either.
That doesn't answer the question. Please visit the link I posted about installing SSL libraries in your staging or production environment and retry your PDFs.
openssl version
OpenSSL 1.1.1 11 Sep 2018
Does this it?
cat Gemfile.lock | grep wkhtmltopdf
wkhtmltopdf-binary (0.12.3.1)
wkhtmltopdf-binary
I did use absolute path on both localhost and production, aka 'https://cloudinary.com/image.jpg' Still absolute path to extern domain works on local, but doesn't in production/staging
Please upgrade your wkhtmltopdf-binary gem to the current version and report back. There are lots of changes between 0.12.3.1 and 0.12.5.4.
updating wkhtmltopdf-binary
gem to 0.12.6 fix the issue
Oh my, Om deeply sorry - update to 0.12.5.4. solved all my troubles, I wanted to comment but apparently I forgot =(
I can confirm using 0.12.6.2 with an image tag of = wicked_pdf_image_tag image_url("image_name")
with an image hosted on S3 that it is properly rendering.
works as expected after update version, thanks 👍🏼