Forum


Replies: 2   Views: 139
How to improve merging process ?

Posted by Bouillou  · 01-11-2024 - 14:26

Dear support,

I've been using PHPDocX for a long time, and I'd like your advice on one of my processes. 

I often have mass mailings letter containing 100 pages to create using a Word template.

Here's my process:

1) Load a specific template containing ~20 variables, a header with a small image, a footer with text and few variables and font customization with "CreateDocxFromTemplate"

2) Replace variables

3) Save the document in a specific folder pending merging

4) Repeat steps 1, 2 and 3 with the same template 100 times

5) Merge all documents to create the final document (with MultiMerge class), then delete individual files.

This process works well, but when the template size is 200kB (because of the header logo for example), the final document size is 200kB * 100 small files merged together => 20MB.

I'm sure I could improve this process to reduce the final file size as the template is always the same for all my 100x individual files.

Could you please give me your advice?

Posted by admin  · 01-11-2024 - 17:53

Hello,

You could use optimizeDocx to optimize the final DOCX output and reduce its size.

If the headers are the same for all DOCX documents, the easiest approach would be to remove them from the documents to be merged, then do the merging, and finally import the headers/footers using importHeadersAndFooters.

If you also want to improve the performance, Premium licenses allow using in-memory DOCX documents (https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents).

Regards.

Posted by Bouillou  · 04-11-2024 - 14:47

Thank you for sharing this. I will try your suggestions.

Best regards