class HexaPDF::Document::Files

Included Modules

This class provides methods for managing file specifications of a PDF file.

Note that for a given PDF file not all file specifications may be found, e.g. when a file specification is only a string. Therefore this module can only handle those file specifications that are indirect file specification dictionaries with the /Type key set.

Public Class Methods


Creates a new Files object for the given PDF document.

Public Instance Methods

add(filename, name: nil, description: nil, embed: true) → file_spec
add(io, name:, description: nil) → file_spec

Adds the file or IO to the PDF document and returns the corresponding file specification object.



The name that should be used for the file path. This name is also used for registering the file in the EmbeddedFiles name tree.

When a filename is given, the basename of the file is used by default for name if it is not specified.


A description of the file.


When an IO object is given, it is always embedded and this option is ignored.

When a filename is given and this option is true, then the file is embedded. Otherwise only a reference to it is stored.

See: HexaPDF::Type::FileSpecification

each(search: false) {|file_spec| block } → files
each(search: false) → Enumerator

Iterates over indirect file specification dictionaries of the PDF.

By default, only the file specifications in their standard locations, namely in the EmbeddedFiles name tree and in the page annotations, are returned. If the search option is true, then all indirect objects are searched for file specification dictionaries which can be much slower.