Question

I need a repeating image to be shown on every page of the pdf. The only solution to this I've found so far is putting it into the header using

%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}

Works fine but the image is bigger than the header size. Is there any way I can increase the height of the header or put a repeating image somehow outside the header?

Thanks!

Was it helpful?

Solution 2

I ended up adding this code

PDFKit.configure do |config|
  config.default_options = {
    :page_size     => 'Letter',
    :margin_top    => '3.6in',
    :margin_right  => '0.3in',
    :margin_bottom => '1.3in',
    :margin_left   => '0.3in'
  }
end

to /config/initializers/pdfkit.rb. Worked like charm after I restarted the server.

OTHER TIPS

You'll need to tweak the margin-top and header-spacing values. For example:

%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}
%meta{:name => 'pdfkit-margin_top', :content => '3cm' }
%meta{:name => 'pdfkit-header_spacing', :content => '10' }

From the wkhtmltopdf docs:

--header-spacing * <real>         Spacing between header and content in mm
                                  (default 0)
-T, --margin-top <unitreal>       Set the page top margin (default 10mm)

You can put any of the wkpdftohtml options in the meta tags and PDFKit will pass them through.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top