Module: HexaPDF::Task::PDFA

Defined in:
lib/hexapdf/task/pdfa.rb

Overview

Task for creating a PDF/A compliant document.

It automatically

  • prevents the Standard 14 PDF fonts to be used.

  • adds an appropriate output intent if none is set.

  • adds the necessary PDF/A metadata properties.

Constant Summary collapse

SRGB_ICC =

:nodoc:

'sRGB2014.icc'

Class Method Summary collapse

Class Method Details

.add_srgb_icc_output_intent(doc) ⇒ Object

:nodoc:



76
77
78
79
80
81
82
# File 'lib/hexapdf/task/pdfa.rb', line 76

def self.add_srgb_icc_output_intent(doc) # :nodoc:
  icc = doc.add({N: 3}, stream: File.binread(File.join(HexaPDF.data_dir, SRGB_ICC)))
  doc.catalog[:OutputIntents] = [
    doc.add({S: :GTS_PDFA1, OutputConditionIdentifier: SRGB_ICC, Info: SRGB_ICC,
             RegistryName: 'https://www.color.org', DestOutputProfile: icc}),
  ]
end

.call(doc, level: '3u') ⇒ Object

Performs the necessary tasks to make the document PDF/A compatible.

level

Specifies the PDF/A conformance level that should be used. Can be one of the following strings: 2b, 2u, 3b, 3u.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hexapdf/task/pdfa.rb', line 61

def self.call(doc, level: '3u')
  unless level.match?(/\A[23][bu]\z/)
    raise ArgumentError, "The given PDF/A conformance level '#{level}' is not supported"
  end
  doc.config['font_loader'].delete('HexaPDF::FontLoader::Standard14')
  doc.register_listener(:complete_objects) do
    part, conformance = level.chars
    doc..property('pdfaid', 'part', part)
    doc..property('pdfaid', 'conformance', conformance.upcase)
    add_srgb_icc_output_intent(doc) unless doc.catalog.key?(:OutputIntents)
  end
end