File: alternate_page_numbering.rb

package info (click to toggle)
ruby-prawn 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,220 kB
  • ctags: 826
  • sloc: ruby: 14,469; sh: 43; makefile: 18
file content (32 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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