Module: Idml::Render::PdfaPacket

Defined in:
lib/idml/render/pdfa_packet.rb

Overview

Builds the PDF/A-2a XMP packet and attaches it to the PDF Catalog as the /Metadata stream. PDF/A requires:

1. An XMP  stream on `/Catalog` (not just `/Info`).
2. The packet must declare `pdfaid:part` and `pdfaid:conformance`.
3. `dc:format` must be `application/pdf`.

ICC profile (output intent) embedding is handled separately by OutputIntents#embed_icc — see TODO 77 for the deferred plan to bundle sRGB and register the intent.

The packet is built from the same fields already threaded through PdfrbWriter#set_info, so PDF/A output reuses the XMP-extracted values from the IDML packet (TODO 75).

Constant Summary collapse

PDF_A_PART =
2
PDF_A_CONFORMANCE =
"A"

Class Method Summary collapse

Class Method Details

.attach(document, metadata) ⇒ Object

Attaches the built packet to the document's Catalog as the /Metadata stream and sets /Lang. Idempotent — replaces any existing /Metadata.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/idml/render/pdfa_packet.rb', line 34

def self.attach(document, )
  xmp = 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)
  document.catalog.value[:Lang] ||= "en-US"
end

.build(metadata) ⇒ Object

Returns the XMP packet bytes suitable for a /Metadata stream.

Parameters:

  • metadata (Hash{Symbol => String})

    the Info-dict fields already assembled by the pipeline.



26
27
28
29
# File 'lib/idml/render/pdfa_packet.rb', line 26

def self.build()
  body = rdf_description()
  "#{XMP_BEGIN}#{body}#{XMP_END}"
end