wicked_pdf: footer height/styling
Asked Answered
I

1

7

I'm using the awesome wicked_pdf gem to generate a PDF, but I can't figure out how to change certain styles within the footer.

I'm having a HAML template for the footer looking roughly like this:

!!!
%html
  %head
    %meta{:charset => "utf-8"}
    = wicked_pdf_stylesheet_link_tag "pdf"

  %body
    .footer
      %p Line 1
      %p Line 2
      %p Line 3

And some styles:

.footer {
  padding-top: 1em;
  border-top: 1px solid #ccc;
}

The styles are applied just fine, but the due to a small height of the footer, only the first line is visible. I've tried to set the height via CSS, but no dice so far. If I set a footer using e.g the center, attributes or right supplying text directly, line breaks cause the footer to "grow" as expected.

Any idea on how to modify the footer height?

Iman answered 2/10, 2011 at 14:41 Comment(0)
C
22

You'll have to adjust the bottom margin of the PDF to make room for the footer if it is over a certain size.

respond_to do |format|
  format.pdf do
    render :pdf => 'some_pdf',
           :margin => { :bottom => 30 },
           :footer => { :html => { :template => 'pdfs/footer.pdf.erb' } }
  end
end

or you can throw that margin value in your config/initializers/wicked_pdf.rb file if it is a site-wide thing.

Chrystel answered 3/10, 2011 at 20:26 Comment(2)
Thanks! Makes sense. Can I define anything in the initializer? And will settings made in controllers/mailers override these defaults? Would you have some documentation on this anywhere? Cheers!Iman
Yes. Options defined in the initializer are site-wide, but you can override any of them in the render :pdf call. Options are documented here: github.com/mileszs/wicked_pdfChrystel

© 2022 - 2024 — McMap. All rights reserved.