class HexaPDF::Importer

Parent

The Importer class manages the process of copying objects from one Document to another.

It may seem unnecessary using an importer containing state for the task. However, by retaining some information about the already copied objects we can make sure that already imported objects don’t get imported again.

Two types of indirect objects are never imported from one document to another: the catalog and page tree nodes. If the catalog was imported, the whole source document would be imported. And if one page tree node would imported, the whole page tree would be imported.

See: Document#import

Public Class Methods

copy(destination, object, allow_all: false, source: nil)

Imports the given object (belonging to the source document) by completely copying it and all referenced objects into the destination object.

If the allow_all argument is set to true, then the usually omitted catalog and page tree node objects (see the class description for details) are also copied which allows one to make an in-memory duplicate of a HexaPDF::Document object.

Specifying source is optionial if it can be determined through object.

After the operation is finished, all state is discarded. This means that another call to this method for the same object will yield a new - and different - object. This is in contrast to using ::for together with import which remembers and returns already imported objects (which is generally what one wants).

for(destination)

Returns the Importer object for copying objects to the destination document.

new(destination, allow_all: false)

Initializes a new importer that can import objects to the destination document.

Public Instance Methods

import(object, source: nil)

Imports the given object to the destination object and returns the imported object.

Note: Indirect objects are automatically added to the destination document but direct or simple objects are not.

The source argument should be nil or set to the source document of the imported object. If it is nil, the source document is dynamically identified. If this identification is not possible and the source document would be needed, an error is raised.