Skip to content

Instantly share code, notes, and snippets.

@neumachen
Forked from abhishek77in/report.rb
Created April 26, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neumachen/a7157435a0cb4925e509258288d65dbd to your computer and use it in GitHub Desktop.
Save neumachen/a7157435a0cb4925e509258288d65dbd 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment