Skip to content

Instantly share code, notes, and snippets.

@abhishek77in
Created December 9, 2012 19:31
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save abhishek77in/4246643 to your computer and use it in GitHub Desktop.
Save abhishek77in/4246643 to your computer and use it in GitHub Desktop.
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
Copy link

chundo commented Mar 7, 2015

very weel

@irvingprog
Copy link

This helped me a lot.

Thanks

Irving R.

@rodridevops
Copy link

Thanks mate, it really helped to me

@saranicoly
Copy link

Thank you, it helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment