Class: Arrolio::Renderer::LinkAnnotator
- Inherits:
-
Object
- Object
- Arrolio::Renderer::LinkAnnotator
- Defined in:
- lib/arrolio/renderer/link_annotator.rb
Overview
Collects hyperlink annotations during rendering and emits them
as /Annot entries on each PDF page. The renderer calls
record_link for each text run that has an href; after the
page is fully rendered, flush emits the /Annots array.
Defined Under Namespace
Classes: Link
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#pending_links ⇒ Object
readonly
Returns the value of attribute pending_links.
Instance Method Summary collapse
-
#flush(pdfrb_page) ⇒ Object
Emits collected links as /Annot entries on the given pdfrb page.
-
#initialize(document) ⇒ LinkAnnotator
constructor
A new instance of LinkAnnotator.
- #record_link(x:, y:, width:, height:, uri:) ⇒ Object
Constructor Details
#initialize(document) ⇒ LinkAnnotator
Returns a new instance of LinkAnnotator.
14 15 16 17 |
# File 'lib/arrolio/renderer/link_annotator.rb', line 14 def initialize(document) @document = document @pending_links = [] end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
12 13 14 |
# File 'lib/arrolio/renderer/link_annotator.rb', line 12 def document @document end |
#pending_links ⇒ Object (readonly)
Returns the value of attribute pending_links.
12 13 14 |
# File 'lib/arrolio/renderer/link_annotator.rb', line 12 def pending_links @pending_links end |
Instance Method Details
#flush(pdfrb_page) ⇒ Object
Emits collected links as /Annot entries on the given pdfrb page. Clears the pending list after emitting.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/arrolio/renderer/link_annotator.rb', line 25 def flush(pdfrb_page) return if @pending_links.empty? annots = @pending_links.map { |link| build_link_annot(link) } existing = pdfrb_page.value[:Annots] if existing.is_a?(Array) existing.concat(annots) else pdfrb_page.value[:Annots] = annots end @pending_links.clear end |