I'm new to docx4j and i have a doubt how i can insert a new page to document. Actually i have a looping that fill my document with values but i need to insert a new page to fill next values.
How can i do it?
- Code: Select all
public byte[] criarArquivo(File[] imagens, Collection<StepTO> objs) {
try {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
for(StepTO stepTO : objs){
mainDocumentPart.addParagraphOfText("Step: " + stepTO.getStStepName());
mainDocumentPart.addParagraphOfText("Data Execução: " + new SimpleDateFormat("dd/MM/yy").format(stepTO.getStExecutionDate()));
for(File file : imagens){
if(file.getName().contains(String.valueOf(stepTO.getStId()))){
mainDocumentPart.addObject(createImage(wordMLPackage, file.getAbsolutePath()));
}
}
// HERE SHOULD BE A NEW PAGE DO NEXT OBJECT ON LOOP
}
System.out.println("Saved.");
wordMLPackage.save(new java.io.File("D:\\ad22.docx") );
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
return null;
}
}
Thanks.
David