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

Free Support Forum - aspose.com

Inserting document change section break from continuous to nextpage

Hi, I’m trying to insert a document into another. The master document has some text and a section break “next page”, in the new page there is a paragraph after which i would like to insert the second document. This second document starts with a section break “continuous”, but after inserting it in the master document, this section become “next page”. Any idea why? Can i solve this?

This is the piece of code, i’ve attacched the two word documents.
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”;”>public class TestAsposeSectionChanged {
public static void main(String[] args) {

try {
Document masterDocument = new Document(master_document_path”);
Document partToBeInserted = new Document(“document_part_path”);
DocumentBuilder output = new DocumentBuilder(masterDocument);
Node nodeAfterWichInsertDocumentPart = ((Section)output.getCurrentSection().getNextSibling()).getBody().getFirstChild().getNextSibling();
output.moveTo(nodeAfterWichInsertDocumentPart);
output.insertDocument(partToBeInserted, ImportFormatMode.USE_DESTINATION_STYLES);
masterDocument.save(“merged_document_path);
} catch (Exception e) {
throw new RuntimeException();
}
}
}

Hi Matteo,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert document (master_document.docx) at the end of “master_document.docx” using MS Word, you will get the same output.

In your case, we suggest you please remove the first section of “master_document.docx” if it is empty to get the desired output. Please let us know if you have any more queries.

Hi Tahir,

ok, but i’ve tried another approach changing the section breaks in the document. I’ve a master document with three section break “next-page” and after the third, i would like to insert a document that starts with a section break “continuous”. Using MS Word, i got the expected output, so the session break “continuous” in the document i’ve included become “next-page”. With Aspose instead, also the third “next-page” section of the master document was changed and it became “continuous”. Any idea why?
Here is the code.
I attach also the two documents.
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”;”><pre style=“font-family: “Courier New”;”>public class TestAsposeSectionChanged {
public static void main(String[] args) {

try {
Document masterDocument = new Document(master_document_path”);
Document partToBeInserted = new Document(document_part_path”);
DocumentBuilder output = new DocumentBuilder(masterDocument);
Section currentSection = (Section) output.getCurrentSection().getNextSibling();
Section mySection = (Section) currentSection.getNextSibling().getNextSibling();
Node nodeAfterWichInsertDocumentPart = mySection.getBody().getFirstChild();
output.moveTo(nodeAfterWichInsertDocumentPart);
output.insertDocument(partToBeInserted, ImportFormatMode.USE_DESTINATION_STYLES);
masterDocument.save(“merged_document_path”);
} catch (Exception e) {
throw new RuntimeException();
}
}
}
Hi Matteo,

Thanks for your inquiry. We have tested the scenario and have noticed that section break NewPage is changed to continuous after using InsertDocument. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14957. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir,

Thanks for your replay.
I’ve found this issue on aspose.words Java, the tracking issue code you’ve posted seems to be on .Net version.

Thanks
Matteo

Hi Matteo,

Thanks for your inquiry. The same issue will be fixed in Aspose.Words for .Net and Java.

Please note that the latest version of Aspose.Words for Java is completely auto-ported from .NET, i.e. we do not write code for Aspose.Words for Java; it is generated out automatically from C# code of Aspose.Words for .NET. In your case, the issue which was logged with WORDSNET prefix, would be auto resolved for Java variant of Aspose.Words.
Hi Matteo,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-14957) as 'Not a Bug'.

Please set section start of the first section of the source document to SectionStart.NewPage. This will mimic the MS Word's behavior. We have attached the output document with this post for your kind reference.

Document masterDocument = new Document(MyDir + "master_document.docx");
Document partToBeInserted =
new Document(MyDir + "document_part.docx");

DocumentBuilder output =
new DocumentBuilder(masterDocument);

partToBeInserted.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);

Node nodeAfterWichInsertDocumentPart = masterDocument.getLastSection().getBody().getFirstChild();
output.moveTo(nodeAfterWichInsertDocumentPart);
output.insertDocument(partToBeInserted, ImportFormatMode.
USE_DESTINATION_STYLES);
masterDocument.save(
MyDir + "17.2.0.docx");