We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ASPOSE.WORDS AppendDocument overruns into next doc

Occassionally when merging multiple documents together, the previous document content overruns into the first page of the next document instead of starting on a new page (as we want). You can test with simple C# console app using file1.doc, file2.doc, file3.doc after you unzip attachment into c:\NeedFix. See result.doc where file2.doc overruns into file3.doc.
Please fix or advise how to work-around this issue.

class Program
{
    static void Main(string[] args)
    {
        // load license
        Aspose.Words.License license = new Aspose.Words.License();
        license.SetLicense("Aspose.Words.lic");
        // load the template document
        Aspose.Words.Document doc1 = new Aspose.Words.Document("c:\\NeedFix\\file1.doc");
        Aspose.Words.Document doc2 = new Aspose.Words.Document("c:\\NeedFix\\file2.doc");
        Aspose.Words.Document doc3 = new Aspose.Words.Document("c:\\NeedFix\\file3.doc");
        Aspose.Words.DocumentBuilder docBuilder = new Aspose.Words.DocumentBuilder(doc1);
        docBuilder.Document.AppendDocument(doc2, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
        docBuilder.Document.AppendDocument(doc3, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
        docBuilder.Document.Save("c:\\NeedFix\\result.doc");
    }
}

Hi Janet,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. The ImportFormatMode specifies how formatting is merged when importing content from another document.

In your case, I suggest you please use ImportFormatMode as UseDestinationStyles as shown below.

Aspose.Words.Document doc1 = new Aspose.Words.Document(MyDir + "file1.doc");
Aspose.Words.Document doc2 = new Aspose.Words.Document(MyDir + "file2.doc");
Aspose.Words.Document doc3 = new Aspose.Words.Document(MyDir + "file3.doc");
Aspose.Words.DocumentBuilder docBuilder = new Aspose.Words.DocumentBuilder(doc1);
docBuilder.Document.AppendDocument(doc2, Aspose.Words.ImportFormatMode.UseDestinationStyles);
docBuilder.Document.AppendDocument(doc3, Aspose.Words.ImportFormatMode.UseDestinationStyles);
docBuilder.Document.Save(MyDir + "Out.doc");

Moreover, when using the UseDestinationStyles option, if a matching style already exists in the destination document, the style is not copied and the imported nodes are updated to reference the existing style.

The drawback of using UseDestinationStyles is that the imported text might look different in the destination document comparing to the source document. For example, the “Heading 1” style in the source document uses Arial 16pt font and the “Heading 1” style in the destination document uses Times New Roman 14pt font. When importing text of “Heading 1” style with no other direct formatting, it will appear as Times New Roman 14pt font in the destination document.

Using the KeepSourceFormatting option allows to make sure the imported text looks in the destination document exactly like it was in the source document. If a matching style already exists in the destination document, the source style is copied and given a unique name by appending a suffix number to it, for example “Normal_0” or “Heading 1_5”.

The drawback of using KeepSourceFormatting is that if you perform several imports, you could end up with many styles in the destination document and that could make using consistent style formatting in Microsoft Word difficult for this document.

Hope this answers your query. Please let us know if you have any more queries.

Changing to KeepSourceFormatting causes even worse issues. See new attached result file where the file2.doc in result is corrupted from the original. Please provide solution to preserve source formatting but not cause overrun into next file on merge.

Hi Janet,

Thanks for your inquiry. I have tested the scenario using ImportFormatMode as KeepSourceFormatting and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10547. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Janet,

Thanks for your patience. It is to inform you that our development team has completed the work on the issue (WORDSNET-10547) and has come to a conclusion that this issue and the undesired behavior you’re observing is actually not a bug in Aspose.Words.

Please note that Aspose.Words mimics the same behavior as MS Word does. If you merge the documents using MS Word, you will get the same output. Please try to append the contents of file2.doc to file1.doc, the contents of file2.doc will be moved to third page. See the attached image for detail.

Please let us know if you have any more queries.