Insert Page Break after adding section

Hi,


I have a word template document, that contains 3 sections (head, body and footer).
With this code i populate the template :

Document srcDoc = new Document(getPathToTemplateDoc());
Document dstDoc = srcDoc.deepClone();
dstDoc.getSections().clear();
mBuilder = new DocumentBuilder(dstDoc);

String[] fieldsName = {“1”, “2”, “3”, “4”, “5”, “6”, “7”} ;
ResultSet tt = executeQuery(req1) ;
while(tt.next()) {
String[] values = {tt.getString(1), tt.getString(2), tt.getString(3), tt.getString(4), tt.getString(5), tt.getString(6), tt.getString(8)} ;
Document categoryDoc = srcDoc.deepClone();
categoryDoc.getMailMerge().addMergeImageFieldEventHandler(this);
categoryDoc.getMailMerge().execute(fieldsName, values); // Information in head section
String sKey = tt.getString(7) ;
Statement oST = Demo.createStatement() ;
ResultSet oResultSet = oST.executeQuery(req2.replaceAll(“IDX”, sKey )) ;
categoryDoc.getMailMerge().executeWithRegions(“1”, oResultSet) ; // information in a table in body section
oST.close() ;
appendDoc(dstDoc, categoryDoc);
}

/*Append Method is */
private void appendDoc(Document dstDoc, Document srcDoc) throws Exception
{
for (int i = 0; i < srcDoc.getSections().getCount(); i++)
{
Section section = (Section)dstDoc.importNode(srcDoc.getSections().get(i), true);
dstDoc.getSections().add(section);
}
}

I try to add a page break with this instruction : mBuilder.insertBreak(BreakType.PAGE_BREAK) ;
but without success.

Thanks in advance,
Regards,

Anthony

Hello

Thank you for your inquiry.
Please try to set a property
srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE); Here the answer to your question.

And so, instead of your appending method, try to use the method appendDocument from Document object.

Hope this helps.

Perfect, this works.

Thanks you very much.
Regards,

Anthony