We’re encountering a formatting issue when merging DOCX files. After the merge is complete, the footer on every page is positioned slightly lower than it was in the original documents.
We are using the Merger.Merge method with MergeFormatMode.KeepSourceLayout, which we expected would prevent this kind of layout shift.
I have attached two screenshots to illustrate the problem: one shows the correct footer placement before the merge, and the other shows how it has moved down after the merge.
Merger.Merge(mergedOutputPath, generatedDocPaths.ToArray(), SaveFormat.Docx, MergeFormatMode.KeepSourceLayout);
@Srinithin
Cause
The issue you’re experiencing with footer formatting after merging DOCX files is likely due to differences in page setup or footer settings between the original documents. Even when using MergeFormatMode.KeepSourceLayout
, certain layout properties may not be preserved as intended.
Solution
To resolve this issue, you can manually adjust the footer settings after the merge. Here are the steps to follow:
- Check Page Setup: Ensure that the page setup (margins, header/footer distances) is consistent across all documents before merging.
- Adjust Footer Distance: After merging, explicitly set the footer distance for the merged document to match the original documents.
Code
Here’s a code snippet to adjust the footer distance after merging:
Document mergedDoc = new Document(mergedOutputPath);
for (Section section : mergedDoc.getSections()) {
PageSetup pageSetup = section.getPageSetup();
pageSetup.setFooterDistance(20.0); // Set this to the desired distance
}
mergedDoc.save(mergedOutputPath);
Next Steps
- Review the original documents to ensure consistent footer settings.
- Implement the code snippet above to adjust the footer distance after merging.
- Test the output to verify that the footer appears as expected.
If you have any further questions or need additional assistance, please let me know!
Thank you for your support. The original document is accurate. Since I’m utilizing multiple documents for different purposes, modifying this code would affect all of them. Could you please suggest alternative solutions that wouldn’t impact the other documents?
@Srinithin Could you please provide the files you are merging?
Sample document below:
Test_Doc_Word_1.docx (52.5 KB)
Test_Doc_Word_2.docx (52.5 KB)
Mail Merge order
- order 1 - Test_Doc_Word_1.docx
- order 2 - Test_Doc_Word_2.docx
Perform the mail merge and save the document as a PDF
@Srinithin Using MergeFormatMode.KeepSourceFormatting
solves this problem.
I was already using MergeFormatMode.KeepSourceFormatting, but I encountered issues with some documents. Specifically, when using that mode, the footer size appeared larger or mismatched compared to the original document.
I created a support ticket with Aspose, and they suggested using MergeFormatMode.KeepSourceLayout
instead.
Below is the attachment link for your reference.
Footer issues - Free Support Forum - aspose.com
My requirement is that everything remains exactly the same as in the original document after the mail merge in my mail merge document.
@Srinithin
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28445
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as WORDSNET-28445) have been fixed in this Aspose.Words for .NET 25.9 update also available on NuGet.