PDF image header using wicked_pdf gem and wkhtmltopdf

My controller:

  def show
    respond_to do |format|
    format.pdf do
    #render :pdf => "show",:template => "welcome/show",:footer => { :right => 'Page [page] of [topage]' })
    #render :pdf => "show",:template => "welcome/show", :header => {:content => render_to_string({:template => 'welcome/pdf_header.html.erb'})}, :footer=> { :right => 'Page [page] of [topage]' },:margin => { :top => 38, :bottom => 35}
    #render :pdf => "show",:handlers => [:html],:template => "welcome/show.pdf.erb", :header => {:content => render_to_string({:layout => 'pdf_header.html.erb'})}, :footer=> { :right => 'Page [page] of [topage]' },:margin => { :top => 38, :bottom => 35}
    render :pdf => "show",:template => "welcome/show.pdf.erb", :header => {:content => ActionController::Base.new().render_to_string({:template => 'welcome/pdf_header.html.erb', :layout => false})}, :footer=> { :right => 'Page [page] of [topage]' },:margin => { :top => 38, :bottom => 35}
    end 
  end
end

I get the PDF along with the page numbers, but I cannot get the image title.

This is the layout:

pdf_header.html.erb

<%= image_tag  "gla/image.jpg" ,:width => "90",  :height=>"85" %>
<%#= wicked_pdf_image_tag  "gla/image.jpg" %>

As soon as I open pdf_header as an HTML file, I get an image, but as soon as I call the PDF, I can’t display the image

In console I get this

Started GET "/welcome/show.pdf" for 127.0.0.1 at 2014-04-17 09:47:05 +0530
  Processing by WelcomeController#show as PDF
Rendered welcome/pdf_header.html.erb (0.4ms)
***************WICKED***************
Rendered welcome/show.pdf.erb (0.7ms)
Rendered text template (0.0ms)
Sent data show.pdf (1.8ms)
Completed 200 OK in 782ms (Views: 1.3ms | ActiveRecord: 0.0ms)

The commented material is what I tried and did not succeed. Is there any other way to display the image directly in the header by specifying the image path instead of passing it through html?

+1
source share
2 answers

Acc. official documentation

<%= wicked_pdf_image_tag 'path' %> instead of <%= image_tag 'path' %>

this should work for you

<%= wicked_pdf_image_tag  "gla/image.jpg" ,:width => "90",  :height=>"85" %>
+1

:

def wicked_pdf_image_tag(img, options={})
  image_tag "file:///#{WickedPdfHelper.root_path.join('public', 'images', img)}", options
end

, WickedPDF , . , , ..

, " ", . , , , /images.

, URL- , :

<img alt="Image" src="http://localhost:3000/images/gla/image.jpg">

, , , , .

0

All Articles