From f5e08bd27f3cfb04b7fdd7ea8b380258d7b4e879 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Thu, 16 Oct 2014 10:43:07 -0400 Subject: [PATCH] Adding a manual entry for alternate page numbers 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. --- .../alternate_page_numbering.rb | 32 +++++++++++++++++++ .../repeatable_content/repeatable_content.rb | 1 + 2 files changed, 33 insertions(+) create mode 100644 manual/repeatable_content/alternate_page_numbering.rb diff --git a/manual/repeatable_content/alternate_page_numbering.rb b/manual/repeatable_content/alternate_page_numbering.rb new file mode 100644 index 000000000..baa6a0edf --- /dev/null +++ b/manual/repeatable_content/alternate_page_numbering.rb @@ -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 = "" + 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 diff --git a/manual/repeatable_content/repeatable_content.rb b/manual/repeatable_content/repeatable_content.rb index 0c0ec645b..70c9c8152 100644 --- a/manual/repeatable_content/repeatable_content.rb +++ b/manual/repeatable_content/repeatable_content.rb @@ -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.