Forum


Replies: 3   Views: 310
Mergedocx() function - merging generate blank document
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 10-04-2024 - 07:55

Hello,

We recommend you check and run the samples available in the package and the API documentation pages. And also read the available documentation.

For example, from the mergeDocx API documentation (https://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP). The signature of the method:

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

A sample using it:

$merge = new MultiMerge();

$merge->mergeDocx('document.docx', array('second.docx', 'other.docx'), 'output.docx', array());

The mergeDocx method generates the output.docx file with DOCX merged. Please checn and run the samples included in the package.

In your code, you are merging DOCX documents:

$mergeResult = $merge->mergeDocx($INPUT_DIRECTORY . $INPUT_FILE1, array($INPUT_DIRECTORY . $INPUT_FILE2,$INPUT_DIRECTORY . $INPUT_FILE3), $OUTPUT_DIRECTORY . $OUTPUT_FILE, array('mergeType' => 1));

and then you are saving a DOCX with the same file name, so your code overwrites the file generated with mergeDocx:

$output_file_path = $OUTPUT_DIRECTORY . $OUTPUT_FILE;
$docx->createDocx($output_file_path);

As your code hasn't added any content to $docx, an empty document is created.

We also recommend you debug if your code can read and generate all needed files. If you send to contact[at]phpdocx.com the files you are merging we'll test them using mergeDocx.

Regards.