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

user1532866
  • 71
  • 1
  • 2
  • 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? – HargrimmTheBleak Jul 17 '12 at 20:12
  • 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) – Unixmonkey Jul 17 '12 at 21:06
  • 1
    I had the same issue with the footer, problem was my wkhtmltopdf installation: http://stackoverflow.com/questions/12181019/wicked-pdf-footer-not-working/12334202#12334202 – Ginty Sep 08 '12 at 20:36

1 Answers1

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.

anthony
  • 640
  • 1
  • 10
  • 32
ggentzke
  • 341
  • 2
  • 6
  • 1
    this gives me: `config/initializers/wicked_pdf.rb:46:in `': undefined method `render_to_string' for main:Object (NoMethodError)` I'm using rails 3.2.16 – Don Giulio Jul 29 '14 at 12:57
  • `render_to_string` is a method on [ActionController](http://apidock.com/rails/ActionController/Base/render_to_string). It should be defined unless you're outside a controller, of course. – ggentzke Sep 11 '15 at 21:53