Class: Pocketbook::PdfDocument
- Inherits:
-
Object
- Object
- Pocketbook::PdfDocument
- Defined in:
- lib/pocketbook/pdf_document.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document:) ⇒ PdfDocument
constructor
A new instance of PdfDocument.
- #named_destinations ⇒ Object
- #page_count ⇒ Object
- #toc_page_numbers(anchor_ids) ⇒ Object
Constructor Details
#initialize(document:) ⇒ PdfDocument
Returns a new instance of PdfDocument.
9 10 11 |
# File 'lib/pocketbook/pdf_document.rb', line 9 def initialize(document:) @document = document end |
Class Method Details
.open(path) ⇒ Object
5 6 7 |
# File 'lib/pocketbook/pdf_document.rb', line 5 def self.open(path) new(document: HexaPDF::Document.open(path)) end |
Instance Method Details
#named_destinations ⇒ Object
34 35 36 37 38 39 |
# File 'lib/pocketbook/pdf_document.rb', line 34 def named_destinations {}.tap do |output| extract_old_style_destinations(output) extract_name_tree_destinations(output) end end |
#page_count ⇒ Object
13 14 15 |
# File 'lib/pocketbook/pdf_document.rb', line 13 def page_count @document.pages.count end |
#toc_page_numbers(anchor_ids) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pocketbook/pdf_document.rb', line 17 def toc_page_numbers(anchor_ids) return {} if anchor_ids.empty? page_number_by_reference = extract_page_numbers destination_reference_by_id = named_destinations anchor_ids.each_with_object({}) do |anchor_id, output| page_reference = destination_reference_by_id[anchor_id] next if page_reference.nil? page_number = page_number_by_reference[page_reference] next if page_number.nil? output[anchor_id] = page_number end end |