Replies: 5   Views: 2562
Merging removes 2 out of 3 section breaks
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 k.barendrecht  · 11-07-2017 - 13:46

I've successfully created three documents from templates: doc-section-0.docxdoc-section-1.docxdoc-section-2.docx. Each of these contains a section with sectionType 'nextPage' at the end of the first page as seen in the screenshots.

After merging with mergeType: 'continuous' (1) only the section from the first document remains. 

// Merge the first file with the remaining files, mergeTypes: 0 = addSectionAtEnd, 1 = continuous
        (new MultiMerge())->mergeDocx(FILE_OUTPUT_LOCATION, $docxSectionFilesPaths, FILE_OUTPUT_LOCATION, ['mergeType' => 1, 'numbering' => 'continue']);

Why is the merge removing 2/3 section breaks, and how do I prevent this from happening? 

Posted by admin  · 11-07-2017 - 13:59


When you set mergeType as 1, the sections of the merged DOCX are removed. Only the first section is kept (you can read this behaviour on the API page of the method). If you set mergeType as 0, then all sections are preserved.

We recommend you to use the enforceSectionPageBreak available in the method. Or use DOCXPath to add new breaks in the merged DOCX.


Posted by k.barendrecht  · 11-07-2017 - 14:58

Thanks for the quick reply.

Setting mergeType to 0 will always add section breaks, as will setting the option enforcePageBreaks.

I wish to set the section breaks on a per section basis. It seems devious to me to first create the documents, then merge, then modify the merged document. Isn't there a simpler way to achieve section-based page breaks?

Posted by admin  · 11-07-2017 - 16:23


You could call mergeDocx as many times as needed if you need to merge some DOCX keeping the sections and other DOCX being merged as continuous. Premium licenses allow to do all these steps using in-memory, so you don't need to create a merged DOCX file for each step (please check the included samples in your package).

You can use the previous approach or DOCXPath, there's no other solution to accomplish what you need.


Posted by k.barendrecht  · 31-07-2017 - 08:15

Hello admin,

My problem lies with the fact that mergeType 'continuous' actually removes existing sections (except the first). I want to use the existing sections, and not have them removed by merging. Both options dont really work for my case.

Lets say I have the following setup: DocxWithSection->DocxWithoutSection->DocxWithSection.

MergeType Continuous 1 would result in only the first section remaining.

MergeType addSectionAtEnd 0 would result in a double section after the first document and a double section after the last document.

I dont think it's possible to use the original sections and just merge without changing any of the sections as of now, but I think that would be a good addition for this method. (correct me if this is possible)

Greetings, Kars

Posted by admin  · 31-07-2017 - 18:55


If you set mergeType as 1, only the first section is kept; otherwise all sections are kept. All DOCX must have at least one section.

If you send to contact[at] the three DOCX you are merging the dev team will merge them and check the merged output. DOCXPath is very useful to modify document contents of a DOCX, so it may be helpful to accomplish what you need to do.