Remove blank page in docx4j
Posted: Wed Apr 22, 2015 6:06 pm
I need to conditionally remove/add page break in my generated document with docx4j. If page content is fit with the whole page then my added page break creating a blank page. I am using following code to remove page break:
But this removing use-full page break as well. So is there any way where I can check the page content height dynamically? Or track the blank page so I can remove that?
- Code: Select all
List<Object> paragraphs = getAllElementFromObject(template.getMainDocumentPart(),P.class);
for(Object objP:paragraphs) {
P para = (P) objP;
/***/
List<Object> texts = getAllElementFromObject(para,Text.class);
List<Object> brs = getAllElementFromObject(para,Br.class);
if(brs.size()==1 && checkPageBreak((Br)brs.get(0)) && texts.size()== 0)
remove(template.getMainDocumentPart().getContent(), para);
}
But this removing use-full page break as well. So is there any way where I can check the page content height dynamically? Or track the blank page so I can remove that?