use of org.docx4j.wml.SectPr.PgMar in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method setPageMargins.
/**
* Set document page margins to 50 pixels
*/
private void setPageMargins() {
try {
Body body = wordMLPackage.getMainDocumentPart().getContents().getBody();
PageDimensions page = new PageDimensions();
PgMar pgMar = page.getPgMar();
pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setTop(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setRight(BigInteger.valueOf(pixelsToDxa(50)));
SectPr sectPr = factory.createSectPr();
body.setSectPr(sectPr);
sectPr.setPgMar(pgMar);
} catch (Docx4JException e) {
e.printStackTrace();
}
}
use of org.docx4j.wml.SectPr.PgMar in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setPageMargins.
public void setPageMargins(WordprocessingMLPackage wordMLPackage, ObjectFactory factory) {
try {
Body body = wordMLPackage.getMainDocumentPart().getContents().getBody();
PageDimensions page = new PageDimensions();
PgMar pgMar = page.getPgMar();
pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setTop(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setRight(BigInteger.valueOf(pixelsToDxa(50)));
SectPr sectPr = factory.createSectPr();
body.setSectPr(sectPr);
sectPr.setPgMar(pgMar);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.docx4j.wml.SectPr.PgMar in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setDocMarginSpace.
/**
* @Description:设置页边距
*/
public void setDocMarginSpace(WordprocessingMLPackage wordPackage, ObjectFactory factory, String top, String left, String bottom, String right) {
SectPr sectPr = getDocSectPr(wordPackage);
PgMar pg = sectPr.getPgMar();
if (pg == null) {
pg = factory.createSectPrPgMar();
sectPr.setPgMar(pg);
}
if (StringUtils.isNotBlank(top)) {
pg.setTop(new BigInteger(top));
}
if (StringUtils.isNotBlank(bottom)) {
pg.setBottom(new BigInteger(bottom));
}
if (StringUtils.isNotBlank(left)) {
pg.setLeft(new BigInteger(left));
}
if (StringUtils.isNotBlank(right)) {
pg.setRight(new BigInteger(right));
}
}
Aggregations