Forum: Ruby on Rails Top margin on PDF generated with PDF::Writer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Carlos Paramio (Guest)
on 2006-06-13 13:15
(Received via mailing list)
Hi,

A little question. I've written a method that uses PDF::Writer to
generate a PDF document with some images and text. This is the code on
my controller:

def pdf
  gen_pdf
  redirect_to("#{@request.relative_url_root}/pdf/cupones.pdf")
end

private
def gen_pdf
  pdf = PDF::Writer.new(:paper => "A4")
  pdf.margins_cm(0)
  pdf.start_columns(2, 0)
  pdf.select_font "Times-Roman"
  10.times do
    pdf.open_object do |card|
      pdf.save_state
      pdf.image "public/images/card.png", :justification => :left,
:width => PDF::Writer.cm2pts(10.5), :height => PDF::Writer.cm2pts(6)
      #pdf.add_text_wrap(0, pdf.y, PDF::Writer.cm2pts(1), "Test1", 12,
:left, 0)
      #pdf.add_text_wrap(PDF::Writer.cm2pts(8.5), pdf.y,
PDF::Writer.cm2pts(6), "Test2", 12, :center, 90)
      pdf.restore_state
      pdf.close_object
      pdf.add_object(card, :this_page)
    end
  end
  pdf.save_as("public/pdf/cupones.pdf")
end

But the generated pdf has a top margin of 36pt, and the cards are then
printed in two pages. I need a margin of 0 for the page, to ensure
that all that cards are printed at the same page.

Also, a couple of cards are printed one on top of the other partially.
The others are placed correctly.

Any idea? Thanks!
--
Carlos Alberto Paramio Danta               .--.
http://www.sinfoniadebits.com/            |o_o |
email : carlosparamio @ gmail.com         |:_/ |
jabber: parax @ jaim.at                  //   \ \
----------------------------------------( |    | )--
Fingerprint 41C6 D2BE 7DE7 AB61 C23F    /'\_   _/`\
            F697 5A1D 1849 01B8 D318    \___)=(___/
Ioana Kanda (Guest)
on 2006-06-13 13:50
(Received via mailing list)
Hi,
Maybe this would help:

pdf.margins_cm 0
pdf.y = pdf.absolute_top_margin
Carlos Paramio (Guest)
on 2006-06-13 14:37
(Received via mailing list)
Great! Thanks a lot.

2006/6/13, Ioana Kanda <kaio4000@gmail.com>:
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Carlos Alberto Paramio Danta               .--.
http://www.sinfoniadebits.com/            |o_o |
email : carlosparamio @ gmail.com         |:_/ |
jabber: parax @ jaim.at                  //   \ \
----------------------------------------( |    | )--
Fingerprint 41C6 D2BE 7DE7 AB61 C23F    /'\_   _/`\
            F697 5A1D 1849 01B8 D318    \___)=(___/
This topic is locked and can not be replied to.