Word Font Get Changed When Appending 2 Word Documents

Hi,

We are doing the following scenario which lead to font change :

  1. We create a new document using DocumentBuilder
  2. We fill the new document with the content of an external word document which has paragraphs using Time New Romain size 10.
  3. We fill again the new document with the content of another external word document which has also paragraphs with Time New Roman with size 10.
  4. We save the end result.

The issue is: at the result document, all the content imported from the second external document has been transformed from Time New Roman to Cambria. The size changed too.

Here attached the implementation causing the problem.

Thank you for your help.

Hi Jawad,

Thanks for your inquiry.

In your case, each document to be joined has defined it’s own defaults e.g. the destination document has different default-formatting from what is specified in Part2.docm document. This is because when you import content from source document into destination document, it misses the font formatting options that should be defined in destination document and therefore the imported content instead assumes the font formatting from the destination document.

To work around this problem, instead of importing the source document content to the destination document, the destination document can instead be prepended to the beginning of the source document. This will result in the same joined document but the source document is the one which content is imported into; instead of the destination document. Please see the following code snippet:

string path = @"C:\Temp\AsposeWordFontLost\part1.docm";
string path2 = @"C:\Temp\AsposeWordFontLost\part2.docm";
string pathResult = path.Replace(".docm", "SavedWithAspose.docm");
Document dstDoc = new Document(path2);
Section sec = dstDoc.FirstSection;
sec.Body.ChildNodes.Insert(0, new Paragraph(dstDoc));
Paragraph afterNode = sec.Body.FirstParagraph;
Document srcDoc = new Document(path);
InsertDocument(afterNode, srcDoc);
sec.Body.FirstParagraph.Remove();
dstDoc.Save(pathResult);

I hope, this helps.

Best regards,

Thank you for your response.

Unfortunately, we cannot implement your suggestion. We cannot not join documents (whatever part 2 to part 1 or part 350 to part part 400). We must absolutely use a new document builder to create our final document the way it is in my example (top down approach: part1 > part2 > part3 etc). Hence, we need to make the attached sample works.
Keep in mind my example has only 2 word documents just to show the issue. But in real life, we are creating a word document from hundreds (or thousands) of a mix of Word, Excel, PDF,… documents which means we cannot join document as in your example.

I think it is an Aspose.Word bug. You can confirm it in-house or can you provide a workaround that can be added to my sample to make it work.

Thank you,

Hi Jawad,

Thanks for the additional information. But, when you create an empty document using Microsoft Word 2013, copy all content from part1.docm into it and then copy all content from part2.docm at the end, you’ll notice that Microsoft Word 2013 application also changes the Font from ‘Times New Roman’ to ‘Calibri Light (Headings)’. This seems to be an expected behaviour. Please see my previous reply for details and let me know if I can be of any further assistance.

Best regards,