Free Support Forum - aspose.com

AppendDocument adding empty paragraph break

Hi,


When I use AppendDocument (Aspose.Words 10.4.0.0) on a source file that has embedded page breaks, an empty paragraph break is inserted after each page break in the destination.


Here is the code:


string MyDir = @"C:\Aspose Issue\AppendDocumentAddsEmptyPara\bin\";

Document dstDoc = new Document(MyDir + "Document.docx");

// The document to append.

Document srcDoc = new Document(MyDir + "FivePages.docx");

// Append the source document to the destination document.

// Pass format mode to retain the original formatting of the source document when importing it.

dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

// Save the document.

dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");

I’ve attached code and documents.

Thanks

Hi

Thanks for your request. This occurs because you are using DOC as output format. If you try using DOCX as output format, you will get the expected behavior.

The reason the this strange issue is that in DOC and DOCX formats page breaks are treated differently. If you try to save your FivePages.docx as DOC in MS Word you will see these paragraph breaks on the next pages.

So you have two options:

1. Use section breaks instead of page breaks.

2. Use DOCX as output format.

Best regards.