Rails 3 and PDFKit. How to specify page size?

前端 未结 3 1482
误落风尘
误落风尘 2021-01-06 18:36

I have been looking in the documentation but can\'t find the answer. How can I specify the page size of my pdf document and what are the available page sizes? I keep on look

3条回答
  •  孤街浪徒
    2021-01-06 18:49

    You can set the page size when creating a new PDF like this:

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

    PDFKit uses WKHTMLTOPDF which in turn uses QPrinter. You can find the available sizes in the QPrinter documentation (there's a bunch), but its pretty safe to say that any size paper you want is available. Also, you can set a custom size if you can't find what you need.

    NB: If you don't set a default option for page_size in a config somewhere AND don't supply one in your method call, PDFKit will use its internal default (Letter). See line 10 of lib/pdfkit/configuration.rb

提交回复
热议问题