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

Free Support Forum - aspose.com

How to keep the page format same after appending the doc

I have 2 documents and want to append it and results should be in the same format of the first document with same page layout. I had attach two documents for reference. please could you provide code snippets for above scenario.

Hi Mahesh,

Thanks for your inquiry. Please use following code example to achieve your requirements.

// The document that the content will be appended to.
Document dstDoc = new Document(MyDir + "Doc1.docx");
// The document to append.
Document srcDoc = new Document(MyDir + "Doc2.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.KEEP_SOURCE_FORMATTING);
// Save the document. 
dstDoc.save(MyDir + "Out.docx");

Please read following documentation links for your kind reference and let us know if you have any more queries.
https://docs.aspose.com/words/java/insert-and-append-documents/

Hi Tahir
Thanks for the response as i followed the same steps but the output file doesnt have a same page layout as append1.doc with red borders for the page.
Attached output file for reference…

As i want to output file should have red borders for all the pages.

Hi Mahesh,

Thanks for your inquiry. I
have tested the scenario 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-11696. 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.

Thanks Tahir for the response, could you let me know what is earliest time frame the issue will be resolved/tracked.

Hi Mahesh,

Thanks for your inquiry. I would like to
share with you that issues
are addressed and resolved based on first come first serve
basis. Currently, your issue is under analysis. I am afraid, we can’t provide you any reliable estimate at the
moment. Once your issue is analyzed, we will then be able to provide you
an estimate.

Thanks for your patience and understanding.

Hi Mahesh,

Thanks for your patience. It is to update you that our product team has completed the
analysis of this issue and has come to a conclusion that they won’t be
able to implement the fix to your issue. Your issue has been
closed with ‘‘Won’t Fix’’ resolution.

You are facing the expected behavior of Document.AppendDocument method. This method adds sections of the appending document with preserving their page-setup options. In your case, I suggest you please use DocumentBuilder.insertDocument method as shown below. Hope this helps you.

Document doc1 = new Document(MyDir + "APPEND1.docx");
Document doc2 = new Document(MyDir + "APPPEND2.docx");
DocumentBuilder builder = new DocumentBuilder(doc1);
builder.moveToDocumentEnd();
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.insertDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc1.save(MyDir + "Out.docx");