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

Image not render #940

Open
carlosmedrano97 opened this issue Aug 26, 2020 · 3 comments
Open

Image not render #940

carlosmedrano97 opened this issue Aug 26, 2020 · 3 comments

Comments

@carlosmedrano97
Copy link

Issue description

I'm using a simple

pdf = WickedPdf.new.pdf_from_string("<img alt='logo' style='width: 10%; height: 100%;' src='https://collegeengine.blob.core.windows.net/media/images/logos/CE-Icon_4C.png'>")
save_path = Rails.root.join('filename.pdf')
File.open(save_path, 'wb') do |file|
  file << pdf
end

Added the two gems

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

Expected or desired behavior

The image should be included in the pdf

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf):

wicked_pdf (2.1.0)

wkhtmltopdf version (output of wkhtmltopdf --version):

wkhtmltopdf 0.12.3.2

@belarba
Copy link

belarba commented Sep 17, 2020

change the https to http to test

@unixmonkey
Copy link
Collaborator

@carlosmedrano27 I did a quick test with this on the command-line, and think I discovered what's going on.

echo "<img alt='logo' style='width: 10%; height: 100%;' src='https://collegeengine.blob.core.windows.net/media/images/logos/CE-Icon_4C.png'>" > test.html
wkhtmltopdf test.html out.pdf

will not output your image either, telling me this is not a problem with wicked_pdf, but with the underlying wkhtmltopdf.

Trying to reduce the variables involved, when I removed the style attributes, it started working:

echo "<img alt='logo' src='https://collegeengine.blob.core.windows.net/media/images/logos/CE-Icon_4C.png'>" > test.html
wkhtmltopdf test.html out.pdf

I was able to add back in the width style with style='width: 10%', and that worked too.
However setting the height style, or setting with the height attribute like height='100%', causes the image to not show, where setting height='100' does (which is pixels instead of percent). I even tried setting it in a style tag like <style>img { height: 100%; }</style>, and this also causes the image to not show.

It doesn't even seem to matter if it's in a proper HTML document with doctype & body within a div with a fixed height; it just seems to not like setting a height of 100% on an image in any circumstance I've tried.

It seems to behave the same with wkhtmltopdf version 0.12.3 as well as the newer 0.12.6.

I would suggest you report this to the wkhtmltopdf issue tracker as this could be a legitimate issue, and I'm stumped to why this might be happening. Please link the issue here, so I can keep track of it, too.

Of course you can work around it by omitting that height style in the meantime, as images should be 100% height in relation to the width anyway.

@carlosmedrano97
Copy link
Author

Thanks for your help @unixmonkey, I submitted the issue on the link you provide me, the issue I created is the #4832

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

No branches or pull requests

3 participants