Aspose.Words - AppendDocument appends document continuous not on new page

Hello,

I am merging multiple document into one. I want to add each document at the end of destination document and each should start from new page. Here I want to retain header, footer and styling from source document.

I used DocumentBuilder.AppendDocument. It works for retaining styling and header, footer b

@kautilya Using the DocumentBuilder.AppendDocument method is indeed the correct approach to achieve your desired result. To ensure that the new document is inserted on a new page, please set PageSetup.SectionStart property to SectionStart.NewPage in the first section of the appended document.

Hi Canal,

I tried adding PageBreak before AppendDcoument. Some strange behaviour I can see.
e.g. I am appending two documents into destination document. It adds two page breaks at the end of destination document and then appends two documents continuously. Without any page break.

@kautilya It is likely that the issue occurs because the cursor of the builder needs to be positioned at the end. For instance:

builder.MoveTo(doc.LastSection.Body.LastParagraph);

Anyway, as mentioned in my updated reply, the best approach is likely to set the PageSetup.SectionStart property to SectionStart.NewPage in the first section of the document to be appended.

Thanks Canal, that worked very well. :+1:

1 Like