Paragraph Styles are Changed after Inserting one document into another using Java

I’m using following code to generate new document using two separate document.

public class StyleIssueInTheDocument
{
    public static void main(String[] args) throws Exception
    {
        String basePath = "/home/nobilex/Downloads/";

        Document baseDoc = new Document(basePath + "baseDoc.docx");
        Document workingDoc = new Document(basePath + "Working.docx");
        Document notWorkingDoc = new Document(basePath + "NotWorking.docx");

        generateDoc(baseDoc, workingDoc, basePath + "expected.docx");
        generateDoc(baseDoc, notWorkingDoc, basePath + "not-expected.docx");
    }

    private static void generateDoc(Document baseDoc, Document destDoc, String finalDocName) throws Exception
    {
        baseDoc.copyStylesFromTemplate(destDoc);
        DocumentBuilder documentBuilder = new DocumentBuilder(destDoc);
        documentBuilder.insertDocument(baseDoc, ImportFormatMode.USE_DESTINATION_STYLES);
        documentBuilder.getDocument().save(finalDocName);
    }
} 

files.zip (78.0 KB)

In the above code Working.docx and NotWorking.docx both files are equals but generating different results.

Let me know what are the changes requires in the NotWorking.docx to generate the expected result.

@nobilex

Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using the MS Word, you will get the same output.

Both documents are not equal. Please clear the font formatting of paragraph in both documents. The font name of paragraph is different in both documents.

Please use the following modified code to get the desired output.

private static void generateDoc(Document baseDoc, Document destDoc, String finalDocName) throws Exception
{
    DocumentBuilder documentBuilder = new DocumentBuilder(destDoc);
    documentBuilder.insertDocument(baseDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
    documentBuilder.getDocument().save(finalDocName);
}