module HexaPDF::Task::ImportPages

Task for importing pages from another document that preserves the visual appearance.

It takes care of

  • importing the specified pages with all associated objects,

  • handling optional content groups and their default state,

  • and merging form fields.

Note that the /Order, /AS and /Locked fields of the default optional content configuration dictionary are not preserved.

Example:

doc.task(:import_pages, source: source_doc, pages: [1..-2])

Public Class Methods

call(doc, source:, pages: :all, append: true, ocgs: :preserve, acro_form: :merge)

Performs the necessary steps to import the pages from the source docment into the target document doc. Returns the imported pages.

source

Specifies the source PDF document from which the pages should be imported.

pages

Specifies the pages that should be imported. The argument has to be one of the following:

:all

Imports all pages from the source document.

Integer value

Imports the page with the given zero-based index.

Range value

Imports the pages from the zero-based range.

Array of Integer or Range values

Imports all specified pages or page ranges.

Array of source page objects

Imports the given pages.

:append

Specifies whether the imported pages should be appended to the target document’s page tree.

ocgs

Specifies the handling of optional content groups:

:preserve

Preserve the on/off state for all used OCGs.

:ignore

Ignore the on/off state.

:acro_form

Specifies whether AcroForm fields should be merged into the target document.

:merge

Merge AcroForm fields using the MergeAcroForm task.

:ignore

Ignore AcroForm fields.

preserve_ocgs(doc, source, pages)

Preserves the state of the OCGs found on pages so that the visual appearance in the target document doc is the same as in the source document.