Class: HexaPDF::Type::Catalog

Inherits:
Dictionary show all
Defined in:
lib/hexapdf/type/catalog.rb

Overview

Represents the PDF’s catalog dictionary which is at the root of the document’s object hierarchy.

The catalog dictionary is linked via the /Root entry from the Trailer.

See: PDF2.0 s7.7.2, Trailer

Constant Summary

Constants included from DictionaryFields

DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate

Instance Attribute Summary

Attributes inherited from Object

#data, #document, #must_be_indirect

Instance Method Summary collapse

Methods inherited from Dictionary

#[], #[]=, define_field, define_type, #delete, #each, each_field, #empty?, field, #key?, #to_hash, type, #type

Methods inherited from Object

#<=>, #==, #cache, #cached?, #clear_cache, deep_copy, #deep_copy, #document?, #eql?, field, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, make_direct, #null?, #oid, #oid=, #type, #validate, #value, #value=

Constructor Details

This class inherits a constructor from HexaPDF::Object

Instance Method Details

#acro_form(create: false) ⇒ Object

Returns the main AcroForm object.

  • If an AcroForm object exists, the create argument is not used.

  • If no AcroForm object exists and create is true, a new AcroForm object with default settings will be created and returned.

  • If no AcroForm object exists and create is false, nil is returned.

See: AcroForm::Form



137
138
139
140
141
142
143
144
145
# File 'lib/hexapdf/type/catalog.rb', line 137

def acro_form(create: false)
  if (form = self[:AcroForm])
    form
  elsif create
    form = self[:AcroForm] = document.add({}, type: :XXAcroForm)
    form.set_default_appearance_string
    form
  end
end

#must_be_indirect?Boolean

Returns true since catalog objects must always be indirect.

Returns:



92
93
94
# File 'lib/hexapdf/type/catalog.rb', line 92

def must_be_indirect?
  true
end

#namesObject

Returns the name dictionary containing all name trees of the document, creating it if needed.

See: Names



107
108
109
# File 'lib/hexapdf/type/catalog.rb', line 107

def names
  self[:Names] ||= document.add({}, type: :XXNames)
end

#optional_contentObject

Returns the optional content properties dictionary, creating it if needed.

This is the main entry point for working with optional content, a.k.a. layers.

See: OptionalContentProperties



123
124
125
# File 'lib/hexapdf/type/catalog.rb', line 123

def optional_content
  self[:OCProperties] ||= document.add({OCGs: [], D: {Creator: 'HexaPDF'}}, type: :XXOCProperties)
end

#outlineObject

Returns the document outline, creating it if needed.

See: Outline



114
115
116
# File 'lib/hexapdf/type/catalog.rb', line 114

def outline
  self[:Outlines] ||= document.add({}, type: :Outlines)
end

#page_labels(create: false) ⇒ Object

Returns the page labels number tree.

  • If a page labels number tree exists, the create argument is not used.

  • If no page labels number tree exists and create is true, a new one is created.

  • If no page labels number tree exists and create is false, nil is returned.

See: HexaPDF::Document::Pages



156
157
158
159
160
161
162
# File 'lib/hexapdf/type/catalog.rb', line 156

def page_labels(create: false)
  if (object = self[:PageLabels])
    object
  elsif create
    self[:PageLabels] = document.wrap({}, type: NumberTreeNode)
  end
end

#pagesObject

Returns the root node of the page tree, creating it if needed.

See: PageTreeNode



99
100
101
# File 'lib/hexapdf/type/catalog.rb', line 99

def pages
  self[:Pages] ||= document.add({Type: :Pages})
end