Forum


Replies: 1   Views: 201
Merging documents overlaps header part
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 anushkapachpute  · 28-05-2024 - 07:38

Hello

Actually I am trying to merge 2 documents. Before merging these documents looks fine. But when I try to merge it, after merge it gets disturbed. Like header part is disturbed merged output. I have also added part of my code.

  $coverPagePDF = $INPUT_DIRECTORY . 'cover.docx';
   $indexPagePDF = $INPUT_DIRECTORY . 'glossary.docx';


 if (file_exists($coverPagePDF)) {
        mLog("Cover Page found. Adding to merge process\n");
        $mergeResult = $merge->mergeDocx($coverPagePDF, array(), $OUTPUT_DIRECTORY . $OUTPUT_FILE, array('mergeType' => 0));
        if (!$mergeResult) {
            mLog("Merge failed for cover page\n");
            return;
        }
        $filesAdded[] = $coverPagePDF;
    } else {
        mLog("Cover Page not found\n");
    }

    // Merge index page separately if it exists
    if (file_exists($indexPagePDF)) {
        mLog("Glossary Page found. Adding to merge process\n");
        $mergeResult = $merge->mergeDocx($OUTPUT_DIRECTORY . $OUTPUT_FILE, array($indexPagePDF), $OUTPUT_DIRECTORY . $OUTPUT_FILE, array('mergeType' => 0));
        if (!$mergeResult) {
            mLog("Merge failed for Glossary page\n");
            return;
        }
        $filesAdded[] = $indexPagePDF;
    } else {
        mLog("Glossary Page not found\n");
    }

 

Posted by admin  · 28-05-2024 - 07:44

Hello,

Maybe your documents are using the same style name to apply distinct styles? On https://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP is detailed how styles are merged.

Or the last section of the first DOCX is using a continuous type as explained on https://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP in the mergeType option:

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.

Please send to contact[at]phpdocx.com both DOCX files. We'll check them.

Regards.