Merge or Append Word Documents & Keep Original Font Style (Name, Size etc) in Header Footer using Aspose.Words for Java

Dear Support-Team,

we are using Aspose.Words (Java) to append automatically generated RTF documents for our customer, who doesn’t want to open each document (about 50 RTF files) but rather wants only to open the joined document for printing. So it is absolutely important that formatting of each document does not change during concatenation. This is because the joined document, which includes too many appended documents, cannot be checked and manually corrected at the end. That means, that we rely heavily on each appended document to keep its original formatting.

However, using two documents for testing (Document_with_header_and_footer1.rtf and Document_with_header_and_footer2.rtf) we could observe that the font of the header and footer changed from Arial to Times New Roman after concatenation of these document. When using two other documents (Template_with_header_and_footer1.rtf and Template_with_header_and_footer2.rtf) it worked as expected. Why does Aspose.Words handle these documents differently? Am I doing something wrong? How could I solve the problem that the original font style of Document_with_header_and_footer2.rtf gets lost after appending to Document_with_header_and_footer1.rtf? Is there any solution that could help me to keep the original font style of each document?

Here are the documents and the source code I have used for appending the documents. RTFs_with_Header_Footer.zip (142.8 KB)

I hope you can help me.

@einkaufidv,

Thanks for your inquiry. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20376. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-20376) have been fixed in this Aspose.Words for .NET 20.6 update and this Aspose.Words for Java 20.6 update.

Thanks for your response. Unfortunately, the problem is still there. I have used the Aspose.Words for Java 20.6 and could reproduce the same issue using the documents above. It seems like the Aspose update didn’t fix the problem described above. Is there a way how to analyze the difference between the documents where it is working and the documents where it is not. Our customer was eagerly waiting for this bugfix. Is there a workaround we could use for now?

@einkaufidv,

You are right; we can confirm that the issue is still reproducible when using the latest version of Aspose.Words. To address this problem, we have logged another ticket with ID WORDSNET-20742. We have also logged your above concerns in our issue tracking system and will keep you updated on further updates. We apologize for your inconvenience.

@einkaufidv,

Regarding WORDSNET-20376, it is to inform you that we had added a new public property named ImportFormatOptions.IgnoreHeaderFooter in 20.6 version of Aspose.Words for Java API that allows you to instruct Aspose.Words to ignore source formatting of header footer content during appending Word documents when using ImportFormatMode.KEEP_SOURCE_FORMATTING option. Its value is true by default to mimic MS Word’s behavior. Please try the following Java code:

Document dstDocument = new Document("C:\\Temp\\RTFs_with_Header_Footer\\Document_with_header_and_footer1.rtf");
Document srcDocument = new Document("C:\\Temp\\RTFs_with_Header_Footer\\Document_with_header_and_footer2.rtf");

srcDocument.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
srcDocument.getFirstSection().getHeadersFooters().linkToPrevious(false);
srcDocument.getFirstSection().getPageSetup().setRestartPageNumbering(true);

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setKeepSourceNumbering(true);
importFormatOptions.setIgnoreHeaderFooter(false);

dstDocument.appendDocument(srcDocument, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);

SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.RTF);
dstDocument.save("C:\\Temp\\RTFs_with_Header_Footer\\awjava-20.7-IgnoreHeaderFooter-false.rtf", saveOptions);

Output RTF document generated on our end by using the above Java code is attached here for your reference:

Many thanks.

I have tested it using

importFormatOptions.setIgnoreHeaderFooter(false);

and now it works. Thanks for your help.