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(); } } }
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.
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) {
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.
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.
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);
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.