Module: Arrolio::Renderer::Pdf::Metadata
- Included in:
- Arrolio::Renderer::Pdf
- Defined in:
- lib/arrolio/renderer/pdf/metadata.rb
Overview
Extracted concern: Pdfrb coupling points kept out of the emission path.
Instance Method Summary collapse
- #apply_metadata(metadata) ⇒ Object
-
#attach_xmp_metadata(metadata) ⇒ Object
Emit an XMP metadata packet (RDF/XML) as a stream on the catalog's /Metadata entry.
- #build_outline(context, _pages) ⇒ Object
Instance Method Details
#apply_metadata(metadata) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/arrolio/renderer/pdf/metadata.rb', line 9 def () info = @document.catalog.value[:Info] info ||= @document.add({}) @document.catalog.value[:Info] = info info.value[:Title] = [:title] if [:title] info.value[:Author] = [:author] if [:author] info.value[:Creator] = 'Arrolio (Ruby)' info.value[:Producer] = 'Arrolio + Pdfrb' end |
#attach_xmp_metadata(metadata) ⇒ Object
Emit an XMP metadata packet (RDF/XML) as a stream on the catalog's /Metadata entry. PDF readers use this for Dublin Core properties alongside the legacy /Info dict.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arrolio/renderer/pdf/metadata.rb', line 22 def () xmp = XmpBuilder.new().build stream = @document.add( { Type: :Metadata, Subtype: :XML, Length: xmp.bytesize }, type: Pdfrb::Model::Cos::Stream ) stream.stream = xmp @document.catalog.value[:Metadata] = Pdfrb::Model::Reference.new(stream.oid, stream.gen) rescue StandardError => e Arrolio::Logger.warn "XMP attach failed: #{e.class}: #{e.[0, 80]}" end |
#build_outline(context, _pages) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/arrolio/renderer/pdf/metadata.rb', line 35 def build_outline(context, _pages) entries = context.heading_entries return unless entries&.any? pdfrb_pages = @document.pages.to_a ob = OutlineBuilder.new(document: @document, entries: entries, pdfrb_pages: pdfrb_pages) result = ob.build Arrolio::Logger.debug "outline build returned: #{result.class}" rescue StandardError => e Arrolio::Logger.warn "outline build failed: #{e.class}: #{e.[0,150]}" Arrolio::Logger.debug e.backtrace.first(5).join("\n") end |