Displaying header and footer in all pages containing table

510 views
Skip to first unread message

Samiron

unread,
Aug 22, 2009, 7:23:43 AM8/22/09
to Prawn
Hello all,
I have a table which can take multiple pages to accommodate. Say its
the result sheet of students. And i need to include the school's name
in all pages as a header. In the same way i need something in footer
in all pages throughout the table. But I cant understand how to do
this.
i am writing my code like below:

data = Array.new()
20.times do
data << ["student names ","12"]
end

pdf = Prawn::Document.new do
text "*********RubyOnRails**********", :align => :center
table data, :border_style => :grid,
:headers => ['Column 1', 'Column 2'],
:border_width => 0.5,
:position => :center,
:column_widths => { 0 => 100 }
end
send_data pdf.render, :filename => 'bounding_boxes.pdf', :disposition
=> 'inline'

This table is acquiring 3 pages but how should i include the
"*********RubyOnRails**********" text in all pages instead of only in
the first page.

Thanks in advance. Please help

samironpaul.blogspot.com

Gregory Brown

unread,
Aug 22, 2009, 8:49:24 AM8/22/09
to prawn...@googlegroups.com
Search the archive. This is an ugly spot in Prawn right now.
--
BOOK: http://rubybestpractices.com
TECH: http://blog.majesticseacreature.com
NON-TECH: http://metametta.blogspot.com

wesgarrison

unread,
Aug 24, 2009, 12:47:54 PM8/24/09
to Prawn
I came searching for the same thing.

Searching the group for 'header' gives 5 results and this is the only
pertinent one.
Maybe I don't know the terms to search for, though.

I ended up figuring it out after I found this post, so here's what I
did:

Create a header.
Call canvas() with a bounding box.
Move page margins down to accommodate.

(I'm in landscape mode, fyi:)

@pdf.header @pdf.margin_box.top_left do
@pdf.canvas do
@pdf.bounding_box ([0.5.in, 8.0.in], :width => 10.in, :height =>
0.5.in ) do
@pdf.text "All Client List", :align => :center, :size => 18

@pdf.line_width 2.pt
@pdf.stroke_horizontal_line -0.05.in, 10.0.in
end
end
end

Comments on this approach much appreciated.

-- Wes

On Aug 22, 7:49 am, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> Search the archive.  This is an ugly spot in Prawn right now.
>
>
>
> On Sat, Aug 22, 2009 at 7:23 AM, Samiron<samironp...@gmail.com> wrote:
>
> > Hello all,
> > I have a table which can take multiple pages to accommodate. Say its
> > the result sheet of students. And i need to include the school's name
> > in all pages as aheader. In the same way i need something in footer

gdon

unread,
Sep 4, 2009, 8:38:52 PM9/4/09
to Prawn
Hi!
You no need to use canvas(), just use bounding_box.
Follow an example:

------- BEGIN CODE --------------

Prawn::Document.new(:page_size => "LETTER", :page_layout => :portrait)
do
#THE HEADER
header margin_box.top_left do
text "Here's My Fancy Header", :size => 25, :align => :center
stroke_horizontal_rule
end

#THE FOOTER
footer [margin_box.left, margin_box.bottom + 10] do
stroke_horizontal_rule
move_down 3
text "And here's a sexy footer - #{page_count}", :size => 16
end

#THE DOCUMENT BODY -> MULTI-PAGES TABLE
bounding_box([margin_box.left, margin_box.top - 50],
:width => margin_box.width,
:height => margin_box.height - 60) do
table @huge_data, # BIG ARRAY WITH DATA FROM ACTIVERECORD
:position => :center,
:headers => ["Col 1","Col 2","Col 3"],
:row_colors => :pdf_writer,
:vertical_padding => 2,
:horizontal_padding => 5,
:header_color => "00ffff"
end #END TABLE
end #END BOUNDING_BOX

end.render #END DOCUMENT.NEW

----- END CODE ------------------------

Best Regards.
Gleidisdon F. Duarte.


On Aug 24, 1:47 pm, wesgarrison <wes.garri...@gmail.com> wrote:
> I came searching for the same thing.
>
> Searching the group for 'header' gives 5 results and this is the only
> pertinent one.
> Maybe I don't know the terms to search for, though.
>
> I ended up figuring it out after I found this post, so here's what I
> did:
>
> Create aheader.
> Call canvas() with a bounding box.
> Move page margins down to accommodate.
>
> (I'm in landscape mode, fyi:)
>
> @pdf.h...@pdf.margin_box.top_left do

chiuei

unread,
Sep 8, 2009, 2:06:35 AM9/8/09
to Prawn
Hi,

Thanks, gdon. Your code works!

But i think the "table" formatting code does not requires an "end".
It prompts an extra "end" error.
After removing it, everything works.

Thanks
> > @pdf.hea...@pdf.margin_box.top_left do

gdon

unread,
Sep 8, 2009, 3:32:12 PM9/8/09
to Prawn
You are right.
There is no "end" for "table"...
My bad.

Gledisdon.
Reply all
Reply to author
Forward
0 new messages