adding page number with long table

17 views
Skip to first unread message

macsig

unread,
Aug 28, 2008, 1:26:30 AM8/28/08
to Prawn
Hello, it is still me.

I have a table that occupied several pages (the number changes) and I
would like to add in the right bottom corner the page number. Is it
possible? or I have to wait for version 0.2 where I guess I can add it
into the footer.

If I add text page_count.to_s, :at => [x.y] it adds the number only in
the last page

THANKS for the reply.


Gregory Brown

unread,
Aug 28, 2008, 10:33:20 AM8/28/08
to prawn...@googlegroups.com

For now, you can try this option in your constructor:

:on_page_stop => lambda { |pdf| pdf.text page_count, :at => [x,y }

But be advised it's disappearing in 0.2, and that 0.2 may be released today :)

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

macsig

unread,
Aug 28, 2008, 1:10:04 PM8/28/08
to Prawn
I see, thanks
Waiting for 0.2 I will give it a try, just to see if it works.
Even the gem will be released today?

Thanks again


On Aug 28, 7:33 am, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Aug 28, 2008, 1:19:45 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 1:10 PM, macsig <sigb...@gmail.com> wrote:
>
> I see, thanks
> Waiting for 0.2 I will give it a try, just to see if it works.
> Even the gem will be released today?

I don't know. Because Prawn is alpha software, users will need to
make use of Github to be sure to get the latest developments.
I'll get a gem out soon, but really, I'm hoping people will try out
the stable branch any time new code has been merged, so that they can
help me test.

Otherwise, it's best to wait to use Prawn after 1.0, which will be
ready "When it's ready"

macsig

unread,
Aug 28, 2008, 1:29:25 PM8/28/08
to Prawn
I see,
I'm sure Prawn 1.0 will be stable and a very good piece of code but
unfortunately I have create some PDFs now.

you mean the next gem will be 1.0?



I have tried what you suggest but

Prawn::Document.generate("docs.pdf", :page_size => "A4", :page_layout
=> :landscape, :on_page_stop => lambda { |pdf| pdf.text
page_count, :at => [80,20], :size => 12 })

produces

undefined local variable or method `page_count' for #&lt;Class:
0x33a5f2c&gt;<

am I trying in the right way ?

THANKS AGAIN, I APPRECIATE



On Aug 28, 10:19 am, "Gregory Brown" <gregory.t.br...@gmail.com>
wrote:

Gregory Brown

unread,
Aug 28, 2008, 1:38:31 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 1:29 PM, macsig <sigb...@gmail.com> wrote:
>
> I see,
> I'm sure Prawn 1.0 will be stable and a very good piece of code but
> unfortunately I have create some PDFs now.
>
> you mean the next gem will be 1.0?

No. The next gem will be 0.2, and it will be out soon, but I'm saying
that keep in mind gem snapshots at the moment are a service to
simplify testing the library in its alpha stages, so there is no
release schedule.

> I have tried what you suggest but
>
> Prawn::Document.generate("docs.pdf", :page_size => "A4", :page_layout
> => :landscape, :on_page_stop => lambda { |pdf| pdf.text
> page_count, :at => [80,20], :size => 12 })
>
> produces
>
> undefined local variable or method `page_count' for #&lt;Class:
> 0x33a5f2c&gt;<
>
> am I trying in the right way ?

Hi. No, you're not. Read the documentation.

Gregory Brown

unread,
Aug 28, 2008, 1:45:26 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 1:38 PM, Gregory Brown
<gregory...@gmail.com> wrote:

>> am I trying in the right way ?
>
> Hi. No, you're not. Read the documentation.

Sorry. I see there was a typo in my code. (Though please do consult
the API docs[0])

you need pdf.page_count

This method isn't in the global namespace.

macsig

unread,
Aug 28, 2008, 1:57:18 PM8/28/08
to Prawn

>
> No.  The next gem will be 0.2, and it will be out soon, but I'm saying
> that keep in mind gem snapshots at the moment are a service to
> simplify testing the library in its alpha stages, so there is no
> release schedule.


Sure, I well understand I have asked about the gem because you
said 0.2 will be released soon. And 0.2 has some features I would like
to try (and test) soon.


> Hi.  No, you're not.  Read the documentation.


Actually before posting I did, and the only place where I found
something about :on_page_stop is here:

new(options={})
Creates a new PDF Document. The following options are available:

:page_size: One of the Document::PageGeometry::SIZES
[LETTER]
:page_layout: Either :portrait or :landscape
:on_page_start: Optional proc run at each page start
:on_page_stop: Optional proc run at each page stop
.....
# New document, draws a line at the start of each new page
pdf = Prawn::Document.new(:on_page_start => lambda { |doc|
doc.line [0,100], [300,100] } )

the example looks quite similar to my code to me, the only difference
I can notice is I'm using generate instead new but I guess generate
calls new to create it before rendering it. because of that I don't
understand where I'm wrong.

Could you please let me know where I can find more information about
that in the documentation.

THANKS

Gregory Brown

unread,
Aug 28, 2008, 2:01:35 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 1:57 PM, macsig <sigb...@gmail.com> wrote:
>
>
>>
>> No. The next gem will be 0.2, and it will be out soon, but I'm saying
>> that keep in mind gem snapshots at the moment are a service to
>> simplify testing the library in its alpha stages, so there is no
>> release schedule.
>
>
> Sure, I well understand I have asked about the gem because you
> said 0.2 will be released soon. And 0.2 has some features I would like
> to try (and test) soon.

You can test them now, is the point:
http://github.com/sandal/prawn/tree/stable

That is the codebase that will become 0.2, I'm just doing cleanup
before release.

>> Hi. No, you're not. Read the documentation.
>

> the example looks quite similar to my code to me, the only difference
> I can notice is I'm using generate instead new but I guess generate
> calls new to create it before rendering it. because of that I don't
> understand where I'm wrong.

You need to use pdf.page_count, not page_count. There was a typo in my code.

> Could you please let me know where I can find more information about
> that in the documentation.

Prawn::Document#page_count.

macsig

unread,
Aug 28, 2008, 3:52:46 PM8/28/08
to Prawn
Thank you so much, now it works.

I don't know if you just forgot but without casting page_count it is
not possible to use it as a text.


I wait for the gem.


Have a great afternoon.

---
Sig



On Aug 28, 11:01 am, "Gregory Brown" <gregory.t.br...@gmail.com>
wrote:

Gregory Brown

unread,
Aug 28, 2008, 3:56:43 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 3:52 PM, macsig <sigb...@gmail.com> wrote:
>
> Thank you so much, now it works.

Great

> I don't know if you just forgot but without casting page_count it is
> not possible to use it as a text.

Yup, you're right. When used in a table, cells are autoconverted with
to_s, but this is not the case with text().

General Ruby comment:
Keep in mind when you call to_s, it's not a type cast, it's just
calling the method to_s, which presumably (but in no way is forced) to
return a String. :)

-greg

macsig

unread,
Aug 29, 2008, 1:29:51 PM8/29/08
to Prawn
Hello,
actually even if the page number is now added to each page it is
placed over the table, since the table arrives until the end of the
page so I will wait for Prawn 0.2 gem in order to define an header and
a footer for each page within I place the page number.

I look forward for news about 0.2 gem.

Have a nice day.
Reply all
Reply to author
Forward
0 new messages