Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a PDF Document using Prawn Library with header, footer and page numbering.
require "prawn"
Prawn::Document.generate("report.pdf") do
10.times do
start_new_page
end
repeat :all do
move_down 50
pad(20) { text "This padded both before and after" }
pad(20) { text "This is an awesome page" }
# header
bounding_box [bounds.left, bounds.top], :width => bounds.width do
font "Helvetica"
text "Here's My Fancy Header", :align => :center, :size => 25
stroke_horizontal_rule
end
# footer
bounding_box [bounds.left, bounds.bottom + 25], :width => bounds.width do
font "Helvetica"
stroke_horizontal_rule
move_down(5)
text "And here's a sexy footer", :size => 16
end
end
string = "page <page> of <total>"
# Green page numbers 1 to 11
options = { :at => [bounds.right - 150, 0],
:width => 150,
:align => :right,
:page_filter => (1..11),
:start_count_at => 1,
:color => "007700" }
number_pages string, options
end
@chundo

This comment has been minimized.

Copy link

chundo commented Mar 7, 2015

very weel

@irvingprog

This comment has been minimized.

Copy link

irvingprog commented May 24, 2015

This helped me a lot.

Thanks

Irving R.

@rcordoval

This comment has been minimized.

Copy link

rcordoval commented Nov 4, 2017

Thanks mate, it really helped to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.