Class: Pdfrb::Document::PageLabels
- Inherits:
-
Object
- Object
- Pdfrb::Document::PageLabels
- Defined in:
- lib/pdfrb/document/page_labels.rb
Overview
Page Labels facade. Generates the /PageLabels number tree on the Catalog for custom page numbering (roman numerals, prefixed arabic, etc.).
Usage:
doc.page_labels.set do
style :roman, count: 5 # i, ii, iii, iv, v
style :decimal, prefix: "A-" # A-1, A-2, ...
end
Defined Under Namespace
Classes: LabelRule
Constant Summary collapse
- STYLES =
{ decimal: :D, roman_lower: :r, roman_upper: :R, alpha_lower: :a, alpha_upper: :A, }.freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#commit! ⇒ Object
Build the /PageLabels number tree and set it on the Catalog.
-
#initialize(document) ⇒ PageLabels
constructor
A new instance of PageLabels.
-
#style(style, prefix: nil, start: 1, count: nil) ⇒ Object
Add a page labeling rule for the next batch of pages.
Constructor Details
#initialize(document) ⇒ PageLabels
Returns a new instance of PageLabels.
27 28 29 30 31 |
# File 'lib/pdfrb/document/page_labels.rb', line 27 def initialize(document) @document = document @rules = [] @current_index = 0 end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
25 26 27 |
# File 'lib/pdfrb/document/page_labels.rb', line 25 def document @document end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
25 26 27 |
# File 'lib/pdfrb/document/page_labels.rb', line 25 def rules @rules end |
Instance Method Details
#commit! ⇒ Object
Build the /PageLabels number tree and set it on the Catalog.
52 53 54 55 56 57 |
# File 'lib/pdfrb/document/page_labels.rb', line 52 def commit! return if @rules.empty? nums = build_nums_array document.catalog.value[:PageLabels] = { Nums: nums } end |
#style(style, prefix: nil, start: 1, count: nil) ⇒ Object
Add a page labeling rule for the next batch of pages.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pdfrb/document/page_labels.rb', line 40 def style(style, prefix: nil, start: 1, count: nil) @rules << LabelRule.new( style: STYLES.fetch(style), prefix: prefix, start: start, page_count: count ) @current_index += count if count self end |