Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created August 30, 2009 17:44
Show Gist options
  • Select an option

  • Save practicingruby/178054 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/178054 to your computer and use it in GitHub Desktop.
require "prawn/core"
class Prawn::Document
def go_to_page(k)
jump_to = @store.pages.data[:Kids][k]
@current_page = jump_to.identifier
@page_content = jump_to.data[:Contents].identifier
end
def number_pages(string, position)
page_count.times do |i|
go_to_page(i)
str = string.gsub("<page>","#{i+1}").gsub("<total>","#{page_count}")
text str, :at => position
end
end
end
Prawn::Document.generate("page_totals.pdf") do
text "Hai"
start_new_page
text "bai"
start_new_page
text "-- Hai again"
number_pages "<page> in a total of <total>", [bounds.right - 50, 0]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment