Merging Word Documents with PHPDocX

July 23, 2012

Since the v2.5.3 the PRO+ package incorporates new utilities that, among other things, allow for the full merging of Word documents.

But what do we mean by "full merging"?

The new mergeDocX method preserves, if so chosen:

  • The sections of the merged documents including:
    • Theirs section properties like paper sizes and margins.
    • Their headers and footers with its associated media.
  • All styles, including the ones associated with different lists types as well as headings, tables, paragraphs, etcetera.
  • Embedded images and links.
  • Charts with all their associated data and options.
  • Footnotes, endnotes and comments.

One may also choose to preserve the page numbering of the original documents or set the page numbers to run as they would normally do in a Word document.

Although some of this features may seem pretty simple to implement it is not so because of the interrelationships among them and the sophistication of the OOXML standard.

But, of course, the main goal of the mergeDocx method is to encapsulate all that complexity and let the final user to generate a single Word document out of two other ones in just a couple of lines of code:

require_once 'path /classes/';
$newDocx = new DocxUtilities();
$myOptions = array('mergeType' => 0);
$newDocx->mergeDocx('firstWordDoc.docx', 'secondWordDoc.docx', 'mergedWord.docx', $myOptions);

We hope that you will find of interest this new method that allows to merge sophisticated Word documents so easily.

If you enjoyed this post you might want to subscribe to our RSS Feed!

Download PHPDocX

download PhpDocX

Choose the version that better suits your needs

Click here

Recent Posts

  • February 17, 2014
    To use PHPDocX with Symfony‭ ‬2,‭ ‬you just need to register it in the autoloader using the UniversalClassLoader class.‭ ‬Copy the contents of the...
  • January 13, 2014
    We are happy to announce the release of the 3.7 version of PHPDocX. The main goal of this version is to allow for the generation of "right to left...
  • November 28, 2013
    We are happy to announce the release of the 3.6 version of PHPDocX. This new version includes some changes that improve the core functionality of...
  • October 28, 2013
    We would like to start by saying that, generally speaking, PHPDocX is pretty fast but we do not want that you just take our Word for it (pun...
  • October 18, 2013
    To use PHPDocX within the Zend Framework 2, you just need to follow these steps: 1. Extract the content of the PHPDocX package to a folder inside...