Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wicked_pdf is not rendering header

        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

like image 523
user1532866 Avatar asked Jul 17 '12 19:07

user1532866


1 Answers

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.

like image 62
ggentzke Avatar answered Sep 29 '22 13:09

ggentzke