I searched a lot and getting some results in which some sample code is there but no one is working. All are either getting null pointer exception or if document is generated
I faced this issue and the solution is
We have to use 3.10
final poi jar.
3.9
having this problem.
Please remove jars of previous version and add jars of 3.10
final version in which this bug is fixed.
Jars requires are:
poi-3.10-FINAL.jar
poi-ooxml-3.10-FINAL.jar
Easily available in net:
http://mvnrepository.com/artifact/org.apache.poi/poi/3.10-FINAL
XWPFDocument document = new XWPFDocument();
CTP ctp = CTP.Factory.newInstance();
CTR ctr = ctp.addNewR();
CTRPr rpr = ctr.addNewRPr();
CTText textt = ctr.addNewT();
textt.setStringValue( " Page 1" );
XWPFParagraph codePara = new XWPFParagraph( ctp, document );
XWPFParagraph[] newparagraphs = new XWPFParagraph[1];
newparagraphs[0] = codePara;
CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy( document, sectPr );
headerFooterPolicy.createFooter( STHdrFtr.DEFAULT, newparagraphs );
The above code is working perfectly, please use 3.10 wars those I mentioned above.