Page 1 of 1

Remove blank page in docx4j

PostPosted: Wed Apr 22, 2015 6:06 pm
by testwork2
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:

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?

Re: Remove blank page in docx4j

PostPosted: Thu Apr 30, 2015 8:48 pm
by jason
Crossposted at http://stackoverflow.com/questions/2978 ... -in-docx4j

Please don't do that.