How to set page margins for a text document using apache poi?

I want to set the page margins for a text document created using apache poi-3.9. I found that this can be done using CTPageMar but CTPageMar not allowed. I am using apache poi-3.9

I tried this

 CTSectPr sectPr = document.getDocument().getBody().addNewSectPr(); CTPageMar pageMar = sectPr.addNewPgMar(); pageMar.setLeft(BigInteger.valueOf(720L)); pageMar.setTop(BigInteger.valueOf(1440L)); pageMar.setRight(BigInteger.valueOf(720L)); pageMar.setBottom(BigInteger.valueOf(1440L)); 
+5
source share
2 answers

As far as I understand, the problem is not related to the provided code, it is related to the missing CTPageMar class.

The source of the problem with the missing classes is clearly explained in the Apache POI FAQ :

To use the new OOXML file formats, the POI requires a jar containing the XSD file format [...] You can manually download the jar from the Maven POI repository.

The URL from the frequently asked questions does not work, but you can find the required jar in the central maven repo .

+3
source

To enable the CTPageMar class, you need to add the org.apache.poi:ooxml-schema package to your classpath. The corresponding JAR contains all the schemas. You can find more information here .

+1
source

All Articles