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

Free Support Forum - aspose.com

Additional / Extra page with AppendDocument method (version 9.3.0.0)

I want to append an existing document at the start of a new document, but I get an empty page at the start of the document. Please provide some guidance. Thanks.

Here's the code:

            string fileName = @"C:\newdoc.doc";
Document newdoc = new Document();
_builder = new DocumentBuilder(newdoc);
Document doc = new Document(@"C:\doc1.doc");
_builder.Document.AppendDocument(doc, ImportFormatMode.UseDestinationStyles);
_builder.MoveToDocumentEnd();
_builder.InsertBreak(BreakType.PageBreak);
_builder.Writeln("Hello World should appear on page 2");
_builder.InsertBreak(BreakType.PageBreak);
_builder.Writeln("Hello Universe should appear on page 3");


newdoc.Save(fileName);

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. This occurs because a newly create document is not actually absolutely empty, it contains one section with one empty paragraph. So, to resolve the problem you should just remove all content from the document before appending document:

Document newdoc = new Document();

DocumentBuilder builder = new DocumentBuilder(newdoc);

// Remove all content from the document.

// An empty docuemnt already contains one section with one empty paragraph.

newdoc.RemoveAllChildren();

Document doc = new Document(@"Test001\doc1.doc");

builder.Document.AppendDocument(doc, ImportFormatMode.UseDestinationStyles);

builder.MoveToDocumentEnd();

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Hello World should appear on page 2");

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Hello Universe should appear on page 3");

newdoc.Save(@"Test001\out.doc");

Hope this helps.

Best regards,