I use Apache POI in a Java project. I have worked on a landscape page, with the following code:
private void changeOrientation (XWPFDocument document, String orientation)
{
CTDocument1 doc = document.getDocument ();
CTBody body = doc.getBody ();
CTSectPr section = body.addNewSectPr ();
XWPFParagraph para = document.createParagraph ();
CTP ctp = para.getCTP ();
CTPPr br = ctp.addNewPPr ();
br.setSectPr (section);
CTPageSz pageSize;
if (section.isSetPgSz ()) {
pageSize = section.getPgSz ();
} else {
pageSize = section.addNewPgSz ();
}
pageSize.setOrient (STPageOrientation.LANDSCAPE);
if (orientation.equals ( "landscape")) {
pageSize.setOrient (STPageOrientation.LANDSCAPE);
pageSize.setW (BigInteger.valueOf (842 * 20));
pageSize.setH (BigInteger.valueOf (595 * 20));
}
else {
pageSize.setOrient (STPageOrientation.PORTRAIT);
pageSize.setH (BigInteger.valueOf (842 * 20));
pageSize.setW (BigInteger.valueOf (595 * 20));
}
}
I call the method after creating the document
private void dipl()
{
XWPFDocument document = new XWPFDocument ();
String landscape = "landscape";
changeOrientation (document, landscape);
} // ......
The problem is Word displays a blank portrait page at the beginning of the document before the landscape page. So, how can I avoid creating the blank page?