Skip to content

Commit

Permalink
Adding a manual entry for alternate page numbers
Browse files Browse the repository at this point in the history
It was unclear how to do this, and I had submitted a previous pull
request that did not explore the existing API.

After a bit of work, this was the method that I ended up using. I
wanted to make sure that the manual (which is very helpful) was
updated.
  • Loading branch information
practicingruby committed Oct 16, 2014
1 parent e65c244 commit f5e08bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions manual/repeatable_content/alternate_page_numbering.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# encoding: utf-8
#
# Below is the code to generate page numbers that alternate being rendered
# on the right and left side of the page. The first page will have a "1" in
# the bottom right corner. The second page will have a "2" in the bottom
# left corner of the page. The third a "3" in the bottom right, etc.
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
text "This is the first page!"

10.times do
start_new_page
text "Here comes yet another page."
end

string = "<page>"
odd_options = { :at => [bounds.right - 150, 0],
:width => 150,
:align => :right,
:page_filter => :odd,
:start_count_at => 1 }
even_options = { :at => [0, bounds.left],
:width => 150,
:align => :left,
:page_filter => :even,
:start_count_at => 2 }
number_pages string, odd_options
number_pages string, even_options
end
1 change: 1 addition & 0 deletions manual/repeatable_content/repeatable_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
p.example "repeater", :eval_source => false
p.example "stamp"
p.example "page_numbering", :eval_source => false
p.example "alternate_page_numbering", :eval_source => false

p.intro do
prose("Prawn offers two ways to handle repeatable content blocks. Repeater is useful for content that gets repeated at well defined intervals while Stamp is more appropriate if you need better control of when to repeat it.
Expand Down

0 comments on commit f5e08bd

Please sign in to comment.