

Header_spacing: 52.197, # margin_top converted from px => mm (You can see it as "margin-top: -200px")įooter_spacing: 0, # The top left edge of the footer is already at the right position Margin_bottom: '150px', # Height of the footer, can be px or mm Margin_top: '200px', # Height of the header, can be px or mm Header_html: 'app/views/foo/bar/header.html',įooter_html: 'app/views/foo/bar/footer.html', To add your repeated header and footer files, add or modify these attributes in your PDFKit options hash:.You can actually execute JavaScript before the page is rendered to PDF, and implement things like page numbers in the header or footer.

PDFKit also comes with some custom options that are hard to express in CSS (or are not supported by the Webkit engine that PDFKit internally uses).for controlling page breaks: page-break-before:always page-break-after:always page-break-inside CSS actually has a few print-related directives, e.g.
#PDFKIT OPTINS HOW TO#
There are concepts and formattings that only make sense on paper, so the question is how to implement them if you only have CSS: How to express page breaks, headers, footers, etc. However, you should always have quiet: true to keep your test output and logs clean. You can get a list of supported options by running man wkhtmltopdf. Most options are forwarded to wkhtmltopdf (see below).
#PDFKIT OPTINS PDF#
Quiet: true, # No output during PDF generation This is awesome to get started fast, but details like setting the content disposition (download / inline) or download filename is awkward.Ĭonfigure PDFKit in an initializer: nfigure do |config| Alternatively you can use PDFKit::Middleware and all your Rails routes automagically respond to the.Paths to the stylesheets must be passed separately before calling to_file. You can use your controller to render the body of your PDF to a string and pass it to PDFKit.new.You can then send the PDF using send_file 'google.pdf'. You can have PDFKit render a website by simply calling PDFKit.new('').to_file('google.pdf').How to use it from your Rails application All you need is a pretty print-stylesheet. For you as a web developer this means you can keep using the technology you are familar with and don't need to learn LaTeX.PDFKit Show snapshot converts a web page to a PDF document.
