Hi Team,
With Aspose.Words for Java 15.6, a continuous break is converted to Page break. The word document in Aspose 15.5 is good.
See attached code and documents.
Thanks,
Kumar
public class TestMultipart
{
public static void main(String[] args) throws Exception
{
TestAsposeUtils.setupLicense(TestAsposeUtils.LICENSE_FILE_PATH);
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
writeDocWithBreaks(docBuilder);
int count = doc.getSections().getCount();
int currentSectionIndex = 0;
java.util.List serializedParts = new ArrayList();
java.util.List sectionList = new ArrayList();
boolean continueLoop = true;
while (continueLoop)
{
Section section = doc.getFirstSection();
if (count == 1)
{
docBuilder.moveToDocumentEnd();
docBuilder.insertBreak(BreakType.SECTION_BREAK_CONTINUOUS);
docBuilder.getCurrentSection().getPageSetup().setOrientation(Orientation.PORTRAIT);
continueLoop = false;
}
sectionList.add(section);
doc.getFirstSection().remove();
count = doc.getSections().getCount();
if (count == 1)
{
Document partDocument = new Document();
addSectionsToPartDocument(sectionList, partDocument);
String partPath = “c:/ref_” + currentSectionIndex++ + “.doc”;
int sectionstart = partDocument.getFirstSection().getPageSetup().getSectionStart();
partDocument.getFirstSection().remove();
partDocument.getFirstSection().getPageSetup().setSectionStart(sectionstart);
partDocument.save(partPath);
serializedParts.add(partPath);
sectionList = new ArrayList();
}
}
for (String path : serializedParts)
{
insertIncludeTextField(docBuilder, path);
docBuilder.writeln();
}
doc.updateFields();
TestAsposeUtils.save(doc);
System.out.println(“done”);
}
private static void addSectionsToPartDocument(List sectionsList, Document partDocument) throws Exception
{
for (Section section : sectionsList)
{
Node dstSection = partDocument.importNode(section, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);
partDocument.getSections().add(dstSection);
}
}
private static void insertIncludeTextField(DocumentBuilder docBuilder, String path) throws Exception
{
String field = “INCLUDETEXT “” \* MERGEFORMAT”; //$NON-NLS-1$
field = field.replace("", path); //$NON-NLS-1$
docBuilder.insertField(field, “”); //$NON-NLS-1$
}
private static void writeDocWithBreaks(DocumentBuilder docBuilder) throws Exception
{
// section 1 - ref_0.doc
docBuilder.write(“Line 1”);
docBuilder.writeln();
docBuilder.write(“1 - before section break new page”);
docBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
// section 2
docBuilder.write(“2”);
docBuilder.writeln();
docBuilder.write(“Before section break continuous”);
docBuilder.insertBreak(BreakType.SECTION_BREAK_CONTINUOUS);
// section 3 - ref_1.doc
docBuilder.write(“After section break”);
// section 4
docBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
}
}