Skip to content

Gem 0.12.4 issue with image #148

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

Closed
mrunalgvm opened this issue Sep 28, 2022 · 4 comments
Closed

Gem 0.12.4 issue with image #148

mrunalgvm opened this issue Sep 28, 2022 · 4 comments
Labels

Comments

@mrunalgvm
Copy link

When I try to display an image in a pdf, i've got a square, instead of the image.This works fine on local but when I check on production app it doesn't show image.
Example of code :
<%= wicked_pdf_image_tag image_url(@image_url) %>
And i'm using the pdf_from_string method.
Also I am not using initializer method is that the reason this is breaking.
Also I am so much tired of changing version from 0.12.3 to 0.12.6.2 as per this so i moved to 0.12.4 after seeing this .

@unixmonkey
Copy link
Collaborator

This is very likely due to your setup with wicked_pdf and where the asset is located, and not wkhtmltopdf_binary_gem.

There are many reasons this could be happening for you.

  1. Does image_url(@image_url) generate a fully-qualified image with protocol (http:// or https:// or file://) and host (example.com)?
  2. Does wicked_pdf_image_tag do the same?
  3. Is that image blocked by a requirement to login, or loaded by JS or anything like that?
  4. With newer versions of wkhtmltopdf_binary_gem, you'll want to set enable_local_file_access: true in your WickedPdf.config or your options to WickedPdf.new.pdf_from_string(string, options) if the image is put on the filesystem as part of the rendering to PDF

To properly simulate production asset loading, you should probably precompile your assets and set your host and asset host, or use a staging environment. You could also use bundle open wicked_pdf, and place a debugger, or comment out this line, and inspect the source html files created in your temp directory that are passed to wkhtmltopdf.

Let me know how it goes!

@mrunalgvm
Copy link
Author

  1. Yes this image_url(@image_url) which is method to check protocol (https:// or http://) and host name ( example.com) also this will be changing everytime for different users.
  2. Basically wicked_pdf_image_tag is used to create image tag same as in how we do for HTML.
  3. Image is not blocked by any authentication method or scenario for me, we are not using any JS for rendering image but we are using to display other content on PDF page. ( Also just an info we are using CSS to align an image to particular position)
  4. OK, but we are not storing that in our filesystem. we are handling that image_url through our Database.

Is there any way to tackle of this issue as such I am not using this new version (0.12.6.2) until and unless the size will decrease. Becasue newer version exceded Heroku max slug size for me.

Also strange thing for me is on local its working as expected although the page orientation default goes to landscape instead of portrait after changing version to 0.12.4 and on staging env its not rendering that page orientation as landscape also image is not rendering.

@unixmonkey
Copy link
Collaborator

1-3. If the output of image_url(@image_url) is a fully-qualified URL with protocol and host, then you don't need wicked_pdf_image_tag, and can use just image_tag.

  1. You'll still want to set enable_local_file_access: true in most cases, because wkhtmltopdf creates a PDF from a local cache of files in your tmp directory.

until and unless the size will decrease

This gem provides a bunch of different binaries so that it works on differing platforms. It used to be a lot smaller because there was only one released "fat" binary for linux, along with one for windows and one for MacOS (3 total), but releases changed to be platform-specific.

You can just pick out the one or two binaries you need out of this gem (or from the wkhtmltopdf releases page) and put them in your app/vendor directory, and point to it like WickedPdf.config[:exe_path] = Rails.root.join('app/vendor/wkhtmltopdf'), or install separate gems for production and development like this:

Gemfile

group :development, :test do
  gem 'wkhtmltopdf-binary'
end

group :production do
  gem 'wkhtmltopdf-heroku'
end

Then, when Heroku compiles it's slug, it will exclude development and test gems, and you should be within the slug size limits.

Orientation goes to landscape

Set it up in your config if you want the default to be, and make sure you aren't specifying Landscape in your code somewhere:

WickedPdf.config[:orientation] = 'Portrait'

@yesh4gvm
Copy link

Thanks @unixmonkey sorry for late reply as per your suggestion for keeping wkhtmltopdf-binary and wkhtmltopdf-heroku in developement and production respectively. And its working in our staging env.

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

No branches or pull requests

3 participants