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'm getting the PDF along with page numbers, but I can't get the image header.
This is the layout:
pdf_header.html.erb
<%= image_tag "gla/image.jpg" ,:width => "90", :height=>"85" %>
<%#= wicked_pdf_image_tag "gla/image.jpg" %>
Once I open pdf_header as an HTML file I get the image displayed, but once I call the PDF I'm not able to display the image
In the 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 stuff is what I have tried and not was successful. Is there another way to display an image directly in the header by giving the path of the image instead of passing it via the html?
ActionController::Base.new().render_to_string
instead of justrender_to_string
? I would write as::header => { :html => { :template => 'welcome/pdf_header.html.erb', :layout => false } }
– Homozygotecant convert nil to integer
– Coleoptile