On_page_start method

0 views
Skip to first unread message

thomasdarde

unread,
Aug 27, 2008, 5:54:29 AM8/27/08
to Prawn
Hi there,

I want to define an "on page start" method for a pdf document.
I've been creating a self.page_start method and it seem's it's
properly called :


def self.page_start pdf
end

and for my pdf controller :

pdf = Prawn::Document.new (:on_page_start =>
MoneyPapersController.page_start ,:right_margin => 0)


But how can I interact with the PDF i'm creating ? Is there an object
wich is passed to this method ?

Thanks,

thomasdarde

unread,
Aug 27, 2008, 6:32:55 AM8/27/08
to Prawn
I'm auto-replying to myself :

This will do the trick:

pdf = Prawn::Document.new ( :on_page_start => lambda { |doc|
MoneyPapersController.page_start doc } )

Gregory Brown

unread,
Aug 27, 2008, 9:08:38 AM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 6:32 AM, thomasdarde <thoma...@gmail.com> wrote:
>
> I'm auto-replying to myself :
>
> This will do the trick:
>
> pdf = Prawn::Document.new ( :on_page_start => lambda { |doc|
> MoneyPapersController.page_start doc } )

This will not work on Prawn 0.2, however.

When it is released, instead, do:

pdf = Prawn::Document.new
pdf.header top_left_point, options do
MoneyPapersController.page_start(pdf)
end


-greg

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

thomasdarde

unread,
Aug 27, 2008, 9:13:36 AM8/27/08
to Prawn
Hi Greg,

Thanks for your help.

I've been using prawn 0.2. But I have a problem with the header
function.

Let's imagine I've got 2 fonts in my document, one used in the header,
the other one in the rest of my document.
Prawn will change to my header's font in the header of page 2, but
won't change again to "normal" font for content in page 2.

On Aug 27, 3:08 pm, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Aug 27, 2008, 9:22:05 AM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 9:13 AM, thomasdarde <thoma...@gmail.com> wrote:
>
> Hi Greg,
>
> Thanks for your help.
>
> I've been using prawn 0.2. But I have a problem with the header
> function.
>
> Let's imagine I've got 2 fonts in my document, one used in the header,
> the other one in the rest of my document.
> Prawn will change to my header's font in the header of page 2, but
> won't change again to "normal" font for content in page 2.

I'm not entirely sure that it should. I'm thinking it may be up to
you to avoid destructive actions in your block, otherwise I'm going to
have to save the entire state of the object on every single page.

For your example, try:

original_font = font.name
font "My new font"
....
font(original_font)


I don't mind adding something like

font "Tempory font" do
...
end

but I'll need to think about it. I know this is a problem, but I
really hate the idea of manually saving the state of the PDF all over
the place. It's a mess.

thomasdarde

unread,
Aug 27, 2008, 9:28:55 AM8/27/08
to Prawn
I just want to make a simple pdf with headers, footers and content. It
has multiple colors, multiple fonts and images.
I'm pretty surprised there is no good library in ruby to do this at
the moment.

Prawn seems promising but to close to alpha software for the moment.

But I don't understand to where it is heading ? Having the possibility
to use "destructive" actions in the header is like the basic for my
use (I know I'm not alone, no problem with that !).


On Aug 27, 3:22 pm, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Aug 27, 2008, 9:30:53 AM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 9:28 AM, thomasdarde <thoma...@gmail.com> wrote:
>
> I just want to make a simple pdf with headers, footers and content. It
> has multiple colors, multiple fonts and images.
> I'm pretty surprised there is no good library in ruby to do this at
> the moment.

Don't be rude. Prawn isn't "Too close to alpha software", it's alpha software.

thomasdarde

unread,
Aug 27, 2008, 9:35:33 AM8/27/08
to Prawn
Sorry, I didn't want to be rude, your doing a great job !
When I have more time I'll try to help.


On Aug 27, 3:30 pm, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Aug 27, 2008, 9:39:03 AM8/27/08
to prawn...@googlegroups.com
On Wed, Aug 27, 2008 at 9:28 AM, thomasdarde <thoma...@gmail.com> wrote:

> But I don't understand to where it is heading ? Having the possibility
> to use "destructive" actions in the header is like the basic for my
> use (I know I'm not alone, no problem with that !).

We might be able to do this with some lower level PDF operators. The
issue is mainly that we don't want to save and restore state in Ruby
all the time because it is dog slow and one of the reasons people hate
PDF::Writer.

But... if we can find a way to save state and then restore it later at
the PDF level, we can get a feature like this in without problems.
I'll investigate, but please drop a ticket in Lighthouse with a
request for enhancement to remind me.

Reply all
Reply to author
Forward
0 new messages