class HexaPDF::Type::OptionalContentProperties

Parent

Represents an optional content properties dictionary.

This dictionary is the value of the /OCProperties key in the document catalog and needs to exist for optional content to be usable by a PDF processor.

In HexaPDF it provides the main entry point for working with optional content.

See: PDF2.0 s8.11.4.2

Field Definitions

NameType/Allowed ValuesRequiredDefault Value
OCGsHexaPDF::PDFArray or Arraytrue[]
DHexaPDF::Type::OptionalContentConfiguration or Hashtruenil
ConfigsHexaPDF::PDFArray or Arrayfalsenil

Public Instance Methods

add_ocg(name) → ocg
add_ocg(ocg) → ocg

Adds the given optional content group to the list of known OCGs and returns it. If a string is provided, an optional content group with that name is created before adding it.

See: ocg, OptionalContentGroup

create_ocmd(ocgs, policy: :any_on)

Creates an optional content membership dictionary containing the given optional content group(s).

The optional argument policy specifies the visibility policy:

:any_on/:AnyOn

Content is visible if any of the OCGs are on.

:any_off/:AnyOff

Content is visible if any of the OCGs are off.

:all_on/:AllOn

Content is only visible if all OCGs are on.

:all_off/:AllOff

Content is only visible if all OCGs are off.

See: OptionalContentMembership

default_configuration → config_dict
default_configuration(hash) → config_dict

Returns the default optional content configuration dictionary if no argument is given. Otherwise sets the the default optional content configuration to the given hash value.

The default configuration defines the initial state of the optional content groups and how those states may be changed by a PDF processor.

Example:

optional_content.default_configuration(
  Name: 'My Configuration',
  OFF: [ocg1],
  Order: [ocg_all, [ocg1, ocg2, ocg3]]
)

See: OptionalContentConfiguration

ocg(name, create: true) → ocg or +nil+

Returns the first found optional content group with the given name.

If no optional content group with the given name exists but the optional argument create is true, a new OCG with the given name is created and returned. Otherwise nil is returned.

See: add_ocg

ocgs()

Returns the list of known optional content group objects, with duplicates removed.