module HexaPDF::Task::MergeAcroForm

Task for merging an AcroForm from one PDF into another.

It takes care of

  • adding the fields to the main Type::AcroForm::Form dictionary,

  • adjusting the field names so that they are unique,

  • and merging the properties of the main AcroForm dictionary itself and adjusting field information appropriately.

Note that the pages with the fields need to be imported already.

The steps for using this task are:

  1. Import the pages into the target document and add all imported pages to an array

  2. Call this task using the created array of pages.

Example:

pages = doc.pages.map {|page| target.pages.add(target.import(page)) }
target.task(:merge_acro_form, source: doc, pages: pages)

Public Class Methods

call(doc, source:, pages:)

Performs the necessary steps to merge the AcroForm fields from the source into the target document doc.

source

Specifies the source PDF document the information from which should be merged into the target document.

pages

An array of pages that were imported from source and contain the widgets of the fields that should be merged.

fix_calculate_actions(acro_form, source_form, import_name)

Fixes the calculate actions listed in the /CO entry of the main AcroForm dictionary to use the new names of the fields.

merge_form_dictionary(target_form, source_form, root_field)

Merges the AcroForm source_form into the target_form and returns a mapping of old font names to new ones.