3

I am using apache poi CTPageMar class to set a page margin to some value given by the user. The problem is that I did not find what is the unit of the values that must be passed in the functions setLeft,setRight,setTop and setBottom. I tried cm, pixels, inches but they all seem wrong. Any idea?

XWPFDocument wordDocument = new XWPFDocument(new FileInputStream(input));
CTSectPr sectPr = wordDocument.getDocument().getBody().addNewSectPr();
CTPageMar pageMar = sectPr.addNewPgMar();
pageMar.setLeft(BigInteger.valueOf(left));
pageMar.setTop(BigInteger.valueOf(top));
pageMar.setRight(BigInteger.valueOf(right));
pageMar.setBottom(BigInteger.valueOf(bottom));
wordDocument.write(new FileOutputStream(output));
Ali Masri
  • 67
  • 1
  • 11

1 Answers1

7

The measure unit is Twip (twentieth of an inch point). One twip is 1/1440 inch. So

...
  int twipsPerInch =  1440;
  pageMar.setLeft(BigInteger.valueOf(1 * twipsPerInch));
...

will be 1 inch left margin.

Axel Richter
  • 56,077
  • 6
  • 60
  • 87