wicked_pdf is not rendering header
Asked Answered
C

1

7
        render :pdf => "file_name",
                     :layout      => 'pdf.html.erb',
                     :template    => 'transactions/show.pdf.erb',
                      :wkhtmltopdf => WICKED_PDF_BIN,
                      :show_as_html => true,
                    :layout => 'pdf.html.erb',
                    :header => {:html => { :template => 'shared/header.pdf.erb'}}

PDF is generated fine, unfortunately I do not see the header. I can stick the header in the main layout and it works fine too. It seems to me that the header line above is not being processed. The filename 'header.pdf.erb' does not seem to matter. I can point it to a file that does not exist and it throws no error.

This is Mac OS, Rails 3.2.1, ruby 1.9

Corum answered 17/7, 2012 at 19:55 Comment(3)
What is the command line for wkhtmltopdf in your console log? Do you see anything like Rendered shared/header.pdf.erb within pdf.html.erb in the console?Hostage
Make sure you are using a version of wkhtmltopdf compiled with QT, and perhaps try eliminating your body margin and padding with CSS (which can eclipse the headers & footers)Henke
I had the same issue with the footer, problem was my wkhtmltopdf installation: #12181519Trompe
X
4

You may want to simply render the template as a string and assign it to the header's content. Try this out:

header: {
  content: render_to_string(template: 'header.pdf.haml')
}

It works well for me.

Xerox answered 11/10, 2013 at 17:12 Comment(2)
this gives me: config/initializers/wicked_pdf.rb:46:in <top (required)>': undefined method render_to_string' for main:Object (NoMethodError) I'm using rails 3.2.16Nador
render_to_string is a method on ActionController. It should be defined unless you're outside a controller, of course.Xerox

© 2022 - 2024 — McMap. All rights reserved.