Forum


Replies: 6   Views: 2376
Multimerge mergedocx and total page numbers
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 kobbe  · 20-02-2020 - 06:10

I create two docx files using CreateDocxFromTemplate. They both have page numbering in footer so one shows "1 / 3 pages", the other one show "1 / 2 pages".

I then use MultiMerge mergeDocx using option ['numbering' => 'restart'].

The end result of page numbers becomes this:
1 / 5
2 / 5
3 / 5
1 / 5
2 / 5

The result I would want is this:
1 / 3
2 / 3
3 / 3
1 / 2
2 / 2

Is there any way to fix this?

Posted by admin  · 20-02-2020 - 07:46

Hello,

Instead of inserting the default page-of field, that use NumPages (total number of pages in the document), you need to change the templates to use SectionPages (total number of pages in the section) to get the output you need:

http://www.wordbanter.com/showthread.php?t=80139

Regards.

Posted by kobbe  · 20-02-2020 - 10:32

Thank you. This worked great for the docx.

But when using transformDocument and converting to PDF, the PDF numbering looks weird:

1 / 2
2 / 2
3 / 2 <-- weirdness
1 / 2
2 / 2

Same weirdness if using more pages.

I am using theese settings:

[transform]
method = "libreoffice"
path = "/usr/bin/libreoffice"

Posted by admin  · 20-02-2020 - 10:42

Hello,

What version of LibreOffice are you using? We recommend you to upgrade to the latest release available on https://www.libreoffice.org/

Regards.

Posted by kobbe  · 20-02-2020 - 11:04

I had old version 6.1.3.2. Did just try to upgrade to 6.4.0.3 (on Windows). Same issue after upgrade.

I also have same error on Unbuntu, not sure what version of LibreOffice I use there yet.

This is the word field code:

{SECTIONPAGES \* Arabic \* MERGEFORMAT}

Looks like the result allways is "2".

Posted by admin  · 20-02-2020 - 11:14

Hello,

If the latest release of LibreOffice returns the same output then SECTIONPAGES is not fully supported by LibreOffice yet. In this specific case we can't force LibreOffice to work as needed, as it seems it's a not supported field.

In this case, as alternative approach, you can generate a PDF (using transformDocument and NumPages instead of SectionPages if needed) for each DOCX and then merge them into a single PDF output using mergePdf.

Another approach could be using custom bookmarks instead of merge fields to set the page total: https://www.techrepublic.com/blog/windows-and-office/pro-tip-calculate-the-current-page-number-within-a-section-in-word/ (by inserting a Bookmark ‘section end’ at the end of the template and adding a ‘Reference tab’ to this bookmark in the footer of the template).

Regards.

Posted by kobbe  · 20-02-2020 - 14:04

Thank you!

The idea with use mergePdf instead as alternative approach is very smart. I will probably go for that. :)