mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 647 forks source link

Footer not showing when it is in the attachment #922

Open kinmt1234 opened 4 years ago

kinmt1234 commented 4 years ago

Issue description

First of all, awesome gem. Thanks for your hard work. I have an issue to display the footer when it is in the attachment. Somehow my footer is not appearing.

class UserInvitationMailer < ApplicationMailer
 def send_pdf(invoice)
    attachments["test.pdf"] = WickedPdf.new.pdf_from_string(
          render_to_string(:pdf => "testPdf",
          :template => 'shared/body.pdf.erb',  
          dpi: 300, 
          zoom: 1.25, 
          margin: {top:10, bottom:20}, 
          :footer => {content: render_to_string('shared/footer.html.erb', layout: nil, locals: { invoice: 
          invoice })}
       ),
      {:orientation => 'Landscape'}
    )
 end
end

Expected or desired behavior

Any ideas of how to make footer appear?

System specifications

ruby '2.6.4' wicked_pdf (1.4.0) wkhtmltopdf 0.12.5 (with patched qt) Rails 5.2.2

ruckus commented 4 years ago

Is your footer content the full HTML including DOCTYPE and all that jazz?

It cannot just be partial HTML. It must be a valid standalone HTML document.

unixmonkey commented 4 years ago

It could also be there, but obscured by the page margins or padding. Set a background color and/or a fixed height, and/or set your bottom margin and padding to 0 to see if its there, but covered up.

lsantobuono commented 3 years ago
attachments["attachment.pdf"] = WickedPdf.new.pdf_from_string(
  render_to_string(pdf: 'boleta',
                   template: 'boleta.pdf.slim',
                   layout: "layout_pdf.html",
                   encoding: "UTF-8",
                   page_size: "A4",
                   margin: { top: 25.4, bottom: 25.4, left: 25.4, right: 25.4 }),
  footer: { content: render_to_string('shared/_footer_pdf.pdf.slim',
                    layout: "layout_pdf.html") })

Got it working this way, notice that footer is the second parameter for pdf_from_string, and not one of render_to_string. Also I believe the layout with html tags is required as pointed by @ruckus