Forum: Ruby on Rails Prawn: text at horizontal middle of the page

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.
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2009-01-06 15:23
(Received via mailing list)
How to achieve this, like a horiz. align to center?

I`m trying Prawn to generate PDFs, but having a problem to place a
short text (3 words) at the horiz. middle of the page. This code
places the text 2 or 3 centimeters right from the middle.

Prawn::Document.generate('public/' + dir +
"certificado.pdf", :page_size => "A4", :page_layout => :landscape) do
      bounding_box([0,430], :width => 800, :height => 600) do
        text nome, :size => 28, :align => :center
      end
end

As I change ":width => 800" value, the distance from the middle
changes. I tried to remove width and heigth options, hoping the
bounding_box to fit all the page, but I got a error.


PS: I tried to subscribe to http://groups.google.com/group/prawn-ruby
but it appears it is not accepting subscriptions.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-01-29 19:12
(Received via mailing list)
Sorry for responding to a very ancient post, I almost never read the
Rails list...

On Jan 6, 9:22 am, Tom Lobato <tomlob...@gmail.com> wrote:
>       end
> end
>
> As I change ":width => 800" value, the distance from the middle
> changes. I tried to remove width and heigth options, hoping the
> bounding_box to fit all the page, but I got a error.

Get rid of the bounding box entirely and just do:  text nome, :size =>
28, :align => :center

You were centering your text within the box, not within the page.

> PS: I tried to subscribe tohttp://groups.google.com/group/prawn-ruby
> but it appears it is not accepting subscriptions.

Please re-subscribe.  You probably missed the "Are you human" form
field, which caused you to be denied.

-greg
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2009-02-06 13:58
(Received via mailing list)
Hello Greg!
at first, congratulations! very nice work!

funny, today a tried again to subscribe to the prawn group
and noted the "r u a human?" question. So I subscribed and returned
here,
in the rails talk, to copy my msg to there, then I saw you reply :)

well, here we go...

On 29 jan, 16:11, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> Sorry for responding to a very ancient post, I almost never read the
> Rails list...
>
> Get rid of the bounding box entirely and just do:  text nome, :size =>
> 28, :align => :center
>
> You were centering your text within the box, not within the page.

in really I tried this before, but got a different bad aligment
problem.
Also, I`m using bounding box to position my text. Is there another way
to position text without bounding box?

Moreover, if I keep using the bounding box, how to position it at
exact
center of the page?

PS: when we close this thread, I will copy it digested to the prawn
list.


Thank you,

Tom Lobato
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2009-02-06 15:58
(Received via mailing list)
Solved!

I had to use bounding box to position the text.
The trick is to use the bounding_box parameters:
  :width => bounds.width, :height => bounds.height
instead
  :width => 800, :height => 600
now prawn center the text exactly.

See all the code...

Prawn::Document.generate("Certificado.pdf", :page_size =>
"A4", :page_layout => :landscape) do
      bounding_box([0,430], :width => bounds.width, :height =>
bounds.height) do
        text name, :size => 28, :align => :center
      end
      bounding_box([0,180], :width => bounds.width, :height =>
bounds.height) do
        text "#{local}, #{date}", :size => 20, :align => :center
      end
end
This topic is locked and can not be replied to.