Module: HexaPDF::DictionaryFields

Included in:
Dictionary
Defined in:
lib/hexapdf/dictionary_fields.rb

Overview

A mixin used by Dictionary that implements the infrastructure and classes for defining fields.

The class responsible for holding the field information is the Field class. Additionally, each field object is automatically assigned a stateless converter object that knows if data read from a PDF file potentially needs to be converted into a standard format before use.

The available converter objects can be retrieved or modified via the Field.converters method.

Converter Objects

The methods that need to be implemented by a stateless converter objects are the following:

usable_for?(type)

Should return true if the converter is usable for the given type.

additional_types

Should return nil, a single type class or an array of type classes which will additionally be allowed for the field.

convert(data, type, document)

Should return the converted data if conversion is possible and nil otherwise. The type argument is the result of the Field#type method call and document is the HexaPDF::Document for which the data should be converted.

Since a converter usually doesn’t need to store any data, it can be implemented as a module using class methods. This is how it is done for the built-in converter objects.

Defined Under Namespace

Modules: ArrayConverter, DateConverter, DictionaryConverter, FileSpecificationConverter, IntegerConverter, PDFByteStringConverter, RectangleConverter, StringConverter Classes: Field

Constant Summary collapse

Boolean =

This constant should always be used for boolean fields.

See: PDF2.0 s7.3.2

[TrueClass, FalseClass].freeze
PDFByteString =

PDFByteString is used for defining fields with strings in binary encoding.

See: PDF2.0 s7.9.2.4

Class.new { private_class_method :new }
PDFDate =

PDFDate is used for defining fields which store a date object as a string.

See: PDF2.0 s7.9.4

Class.new { private_class_method :new }