Studiosity / grover

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium
MIT License
923 stars 105 forks source link

How to add a signature on footer #72

Closed staycreativedesign closed 3 years ago

staycreativedesign commented 4 years ago

How can I have it on the footer right hand side to have a line with initials on the bottom?

abrom commented 4 years ago

Not entirely sure I understand your question? If you're asking how you'd have the footer show some text (initials) and have them right aligned, then that's pretty easy. Just set the footer_template to something like:

'<div class='text right'>What ever text you want</div>'

ie:

Grover.new('<some site URI>', footer_template: '<div class='text right'>What ever text you want</div>').to_pdf

or via the global configuration options:

Grover.configure do |config|
  config.footer_template = '<div class='text right'>What ever text you want</div>'
end

....

Grover.new('<some site URI>').to_pdf

Of course if you're using the middleware you'd likely need to use the global configuration option ;)

See https://github.com/Studiosity/grover#header-and-footer-templates for the list of classes available for laying out the header/footer

abrom commented 4 years ago

Please note you would also need to specify display_header_footer: true per https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions

staycreativedesign commented 4 years ago

thank you sir!

staycreativedesign commented 4 years ago

So I have this in my initializer

Grover.configure do |config|
  config.options = {
    format: 'A4',
    display_header_footer: true,
    header_template: "<div class='url'>foobar</div>",
    footer_template: "<span class=;pageNumber'></span>/<span class='totalPages'></span>",
    margin: {
          bottom: 70,
          left: 25,
          right: 35,
          top: 30,
    },
    print_background: true,
    viewport: {
      width: 640,
      height: 480
    },
    prefer_css_page_size: true,
    emulate_media: 'screen',
    cache: false,
    timeout: 0, # Timeout in ms. A value of `0` means 'no timeout'
    launch_args: ['--font-render-hinting=medium'],
    wait_until: 'domcontentloaded'
  }
end

in my controller

  def contract
    html = render_to_string({
      template: 'pages/contract',
      layout: 'contract.haml'
    })
    pdf = Grover.new(html).to_pdf
    send_data pdf
  end

nothing in the footer what I do wrong here?!

abrom commented 4 years ago

Likely related to the invalid HTML class attribute.. semicolon instead of a quote

abrom commented 4 years ago

You'd also likely want to wrap the spans in a div with the text class. The default with chrome is really small text. It's there, you just can't see it unless you zoom right in. Ie

<div class='text'>what ever</div>
abrom commented 4 years ago

that was in my example above ;)

staycreativedesign commented 4 years ago

Thank you sir!

staycreativedesign commented 4 years ago
%footer{:style => "font-size:16px;margin-left: 80%;"}

This hack works

abrom commented 4 years ago

Ok to resolve this @staycreativedesign ?

staycreativedesign commented 3 years ago

Ok to resolve this @staycreativedesign ?

Yes it is :)