mileszs/wicked_pdf — Issue #69: Footer in pdf_from_string
Author: clod81
Created: 2011-12-21 00:01:41+00:00
State: open

I'm using wicked_pdf pdf_from_string inside an action mailer rails 3 model.
The pdf render perfectly doing this:

attachments["pdf.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf.pdf",:template => 'documents/show.pdf.erb')
)

When I try to pass the option :footer, it does not work with these options:

attachments["pdf.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf.pdf", :template => 'pdf/pdf.html.erb', :layout => 'pdfs/pdf',
:footer => {:html => {:template => 'pdf/pdf_footer.html.erb', :layout => 'pdfs/pdf'}, :spacing => -65})
)

Note that :footer option works sweet inside a controller, coming from a controller default 'render' :pdf method.

I ended up doing something like this, but I'd prefer not using gotchas.

File.open("/tmp/wicked_pdf_#{@model.number}.html", 'w+b', 0644) { |f|
f.write render_to_string({:template => 'pdf/pdf_footer.html.erb', :layout => 'pdfs/pdf'})
}
attachments["pdf.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf.pdf", :template => 'pdf/pdf.html.erb', :layout => 'pdfs/pdf'),
:footer => {:html => {:url => "file:///tmp/wicked_pdf_#{@model.number}.html"}, :spacing => -65}
)

Any clue to have this working properly?