1

I tried the code here: How to set page orientation for Word document? but I can't set the page.

XWPFDocument doc = new XWPFDocument();

CTDocument1 document = doc.getDocument();
CTBody body = document.getBody();

if (!body.isSetSectPr()) {
     body.addNewSectPr();
}
CTSectPr section = body.getSectPr();

if(!section.isSetPgSz()) {
    section.addNewPgSz();        //in this part, the "addNewPgSz()" does not appear
}
CTPageSz pageSize = section.getPgSz(); //this part, the "CTPageSz" is not available

I am using apache poi 3.17, I added all the libraries, where could be the problem? Please help. Thank you!

  • 1
    What means "the "CTPageSz" is not available"? Are you saying that `section.getPgSz();` returns `null` although `section.isSetPgSz()` is true? – Axel Richter Jan 30 '18 at 08:02
  • See if https://stackoverflow.com/questions/34897091/error-in-ctpagesz-class-using-apache-poi-java-netbeans-word-document solves your issue – nos Jan 30 '18 at 08:34
  • Thank you! ooxml-schemas was the problem.. Got it fixed! Thank u so much :) – Paulo Pacardo Rellon Jan 31 '18 at 01:37

0 Answers0