Unfortunately at this stage it's not possible to achieve this. Prawn
renders each page as you finish it so it's impossible to go back and add
page number once you've owrked out how many pages you have.
There's been several proposals to fix this, but not much code yet.
-- James Healy <jimmy-at-deefa-dot-com> Tue, 26 May 2009 22:24:48 +1000
It's bad for performance, but this can be done through a double render.
-greg
> Also, be aware that prawn 0.41 will print your footer in whatever font/
> style/size that is in effect when the page break occurs.
> --~--~---------~--~----~------------~-------~--~----~
Yep, you definitely want to use transactional font blocks with
explicit settings in your header / footer.
Our header and footer support sucks, I'm sorry. Leethal implemented
PDF::Wrapper's support, which is much better, but never prepared a
patch. If someone feels up for it, search the archives and submit a
patch.
-greg
Thanks for that. How I ended up using it: http://gist.github.com/205863
On May 29, 2:46 am, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> Our header and footer support sucks, I'm sorry. Leethal implemented
> PDF::Wrapper's support, which is much better, but never prepared a
> patch. If someone feels up for it, search the archives and submit a
> patch.
>
Couldn't find this. Also dug around a little in edge Prawn but didn't
see anything I could easily use for a total page count, so I'll settle
for this workaround for now.
Sorry for the "To: Steve, CC: list" thing btw. Google Groups is only
showing "Reply to author" links in this thread. Anyone know what's up
with that?
You need to implement go_to_page, which is easy.
Then you do something like this:
page_count.times do |i|
go_to_page(i+1)
text "Page #{i + 1} of #{page_count}", :at => [x,y]
end
An easy helper for this will be in Prawn 0.6, but seeing as this is
just a few lines of code to implement, I'm sure someone here can fill
in the details for you.
BTW, for those interested, don't attempt this on the 0.5 codebase,
restructuring in 0.6 makes it much easier.