Forum


Replies: 2   Views: 1265
Enforcesectionpagebreak is not working
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 hotspot22  · 12-02-2021 - 09:46

Hi!

We are using phpdocx 9.5 premium and I think there is an issue with the mergeDocx option enforceSectionPageBreak.

In my case I have a docx document that is used for a bulk letter. So the document has some placeholders that are replaced by phpdocx and at the end all the documents are merged to one.

$merge = new MultiMerge();
$first_document = array_shift($files);
$merge_options = [
        'mergeType' => 0,
        'numbering' => 'restart',
        'preserveStyleDefaults' => true,
        'forceLatestStyles' => false,
        'enforceSectionPageBreak' => true,
        'lineBreaks' => 1
];
$merge->mergeDocx($first_document, $files, $filename, $merge_options);

But in the result document the text of the second document floats into the first document.

As a dirty fix I've added a section page break at the end of the document. So it has a blank last page.

With that fix the merge works correctly. The second document starts on the blank page of document one, the third document starts on the blank page of document two and so on. But at the end of the merged document there is a blank page because of my added section page break. So I need the enforceSectionPageBreak option to work please :)

Any ideas?

Posted by admin  · 12-02-2021 - 10:50

Hello,

The enforceSectionPageBreak option sets the section type tag as nextPage, that request the section to begins on the following page. Maybe some extra setting in the DOCX overwrites the default behaviour of the section?

We have done some quick tests with enforceSectionPageBreak and we get the correct output. Please send to contact[at]phpdocx.com the documents that illustrate your issue so we can check them and try the same script; also, as your username doesn't have any license tied, please send also the username or email that purchased the license you are using.

Regards.

Posted by admin  · 12-02-2021 - 17:02

Hello,

Thanks for sending the requested DOCX. We have done some tests with your document. Although the nextPage option applied to a section is not fully supported in LibreOffice, so it can't force a section break, regular sections as your DOCX uses, generate a section break automatically in MS Word and LibreOffice (enforceSectionPageBreak is more focused to be used when you are merging DOCX that has continuous section as default and it want to be changed when doing the merging).

After checking your DOCX, the problem is that LibreOffice requires starting the documents with a paragraph to handle section breaks automatically correctly, and your document starts with two tables with an absolute position (anchor set to page instead of paragraph), so LibreOffice has some limitations when generating the automatic section breaks.

Due to the restrictions of LibreOffice, you can use the following approaches to get the same output in MS Word and LibreOffice:

  • Add a paragraph before the first table (for example with the minimal size to get the same layout). And we also recommend changing the table anchor to paragraph instead of to page.
  • Force a section break at the bottom of the document.

Regards.