hcarreras
hcarreras

Reputation: 4622

Prawn: how to set document's printable dimensions

I'm generating a pdf with prawn. Basically, I generate the document and I fill it with some images. The problem comes when I download the file and I try to print it. The dimensions are not set to the ones I previously specified.

pdf = Prawn::Document.new(page_size: "A3", margin: PAGE_MARGIN, page_layout: :landscape)

When I try to print it, the default page size is "A4" instead of "A3" How can I solve this? I tried to attach some metadata but it didn't work correctly.

Thanks in advance!

Upvotes: 0

Views: 3319

Answers (2)

Norm
Norm

Reputation: 109

In the case where you're generating the document within its own class, this also works to declare the paper size:

class EnvelopePdf < Prawn::Document
    def initialize(_item_array, _type_of_item)
       super(:page_size => [324, 684], :page_layout => :landscape)   # 4.5" by 9.5", which is No 10 envelopes
   ... application-specific initialization code here ...
    print_the_envelopes
end

Upvotes: 3

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22331

Using prawn 1.3.0:

require "prawn"

pdf = Prawn::Document.new(:page_size => 'A3')

pdf.text "Hello World!"

pdf.render_file("export.pdf")

in terminal:

pdfinfo export.pdf

outputs:

Creator:        Prawn
Producer:       Prawn
Tagged:         no
Form:           none
Pages:          1
Encrypted:      no
Page size:      841.89 x 1190.55 pts
Page rot:       0
File size:      842 bytes
Optimized:      no
PDF version:    1.3

Upvotes: 2

Related Questions