Rails 3 and PDFKit. How to specify page size?

I look in the documentation but cannot find the answer. How to specify the page size of my pdf document and what are the available page sizes? I keep looking and looking, but I cannot find good documentation. Give me the URL or let me know how I can encode any page size in a PDF.

Oh, and I don’t want to do this in any configuration file, because I need to create PDf documents of different sizes.

NOT in the configuration file ...

PDFKit.configure do |config|
config.wkhtmltopdf = `which wkhtmltopdf`.to_s.strip
config.default_options = {
  :encoding=>"UTF-8",
  :page_size=>"A4", #or "Letter" or whatever needed
  :margin_top=>"0.25in",
  :margin_right=>"1in",
  :margin_bottom=>"0.25in",
  :margin_left=>"1in",
  :disable_smart_shrinking=>false
  }
end
+3
source share
3 answers

You can set the page size when creating a new PDF file as follows:

kit = PDFKit.new(source, :page_size => "Legal")

PDFKit WKHTMLTOPDF, , , QPrinter. QPrinter ( ), , , , . , , , .

. page_size - , PDFKit (Letter). . 10 lib/pdfkit/configuration.rb

+4

wkhtmltopdf PDF , , , . wkhtmltopdf, , :

http://doc.trolltech.com/4.6/qprinter.html#PaperSize-enum

, : page_size :

PDFKit.new(html, :page_size => 'Letter')
+2

PDKIT accepts custom sizes:

  PDFKit.configure do |config|
    config.wkhtmltopdf = `which wkhtmltopdf`.strip
    config.default_options = {
          :page_width => '1682',
          :page_height => '2378'
      }
  end

Dimensions should be in millimeters (wkthmltopdf documentation).

+2
source

All Articles