mergeDocx

mergeDocx

ADVANCED / PREMIUM BASIC

Merges Word documents.

Description
public mergeDocx (string $firstDocument, array $documentArray, string $finalDocument, array $options)

This method allows the full merging of DOCX documents.

The merging process preserves:

  • styles
  • images
  • charts
  • lists
  • footnotes and endnotes
  • comments
  • sections with their corresponding headers and footers (optional)

Parameters

firstDocument

The path to the first Word document to merge.

documentArray

Paths array of the Word documents to merge.

finalDocument

The destination path of the merged file.

options

The possible keys and values are (required options are shown with yellow background):

Key Type Description
mergeType int

The possible values are:

  • 0: preserves the sections of the merged document with their respective headers and footers.
  • 1: merges the contents at the end of the last section of the first document.

If the mergeType equals 1 or the last section of the first document is of the "continuous" type, there may be some missalignment of absolutely positioned content in the merged document. This is due to the fact that the absolute positioned content of the second document was layed out with respect the second document page distribution that may change after the merging.

enforceSectionPageBreak bool Enforces a page section break between documents even if the first section type of the merged document is of the continuous type.
numbering string

The possible values are:

  • continue (the numbering continues in the merged document).
  • restart (the original numbering of the second document is preserved).

lineBreaks int Inserts the indicated number of line breaks between the contents of the merging files.
forceLatestStyles bool Keeps the last merged document styles, overwriting the previous styles.
Code samples

Example #1:

The resulting Word document looks like: