wickedpdf not rendering images?

3.2k views Asked by At

i am using wickedpdf gem to generate pdf invoice from the html code.

gems:

gem 'wicked_pdf'
gem "wkhtmltopdf-binary"

gemfile.lock

wicked_pdf (1.0.6)
wkhtmltopdf-binary (0.9.9.3)

in controller:

  def show_pdf_invoice
    respond_to do |format|
      format.html { render :layout => "pdf.pdf.erb" }
      format.pdf do
    render pdf: "show_pdf_invoice", :layout => 'pdf.pdf.erb'
    #render :pdf => "pdf"#, :layout => 'pdf.html.erb'
      end
    end
  end

in views/invoices/show_pdf_invoice.pdf.erb

  <img id="image" src="https://www.google.co.in/logos/doodles/2016/holidays-2016-day-2-6356741311692800-scta.png" alt="logo" /> 
  <%= wicked_pdf_image_tag 'https://www.google.co.in/logos/doodles/2016/holidays-2016-day-2-6356741311692800-scta.png' %>

pdf is getting generated. But the images are not showing. in the place of images empty boxes are coming. unable to find the issue.

3

There are 3 answers

0
Kevin Etore On BEST ANSWER

I've had the same problem, mine was fixed by removing https for http. Have you tried this? and for the Amazon S3 part: You could use gsub for that as in: gsub("https", "http")

0
iguido On

Using Rails 5.2 with Active Storage in combination with Amazon S3 storage I had the same problem. In development on my local machine the images rendered perfectly, but on Heroku they were presented as small empty rectangles.

To get the url from the logo uploaded to Active Storage I used: @my_object.logo.service_url. Which used the standard url with https. As mentioned before, replacing this with http resolved the issue.

Full code used in my pdf generator view:

<%= wicked_pdf_image_tag @my_object.logo.service_url.gsub("https", "http") %>
1
Joshua Pinter On

Two Options

1. Upgrade to wkhtmltopdf 0.12.5.

-or-

2. Install libssl1.0-dev with apt-get install libssl1.0-dev.

See this issue for more information: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001