use of org.docx4j.wml.SectPr 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 in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setDocTextDirection.
/**
* @Description:设置文字方向 tbRl 垂直
*/
public void setDocTextDirection(WordprocessingMLPackage wordPackage, String textDirection) {
if (StringUtils.isNotBlank(textDirection)) {
SectPr sectPr = getDocSectPr(wordPackage);
TextDirection textDir = sectPr.getTextDirection();
if (textDir == null) {
textDir = new TextDirection();
sectPr.setTextDirection(textDir);
}
textDir.setVal(textDirection);
}
}
use of org.docx4j.wml.SectPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setDocVAlign.
/**
* @Description:设置word 垂直对齐方式(Word默认方式都是"顶端对齐")
*/
public void setDocVAlign(WordprocessingMLPackage wordPackage, STVerticalJc valignType) {
if (valignType != null) {
SectPr sectPr = getDocSectPr(wordPackage);
CTVerticalJc valign = sectPr.getVAlign();
if (valign == null) {
valign = new CTVerticalJc();
sectPr.setVAlign(valign);
}
valign.setVal(valignType);
}
}
use of org.docx4j.wml.SectPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setDocumentBorders.
/**
* @Description: 设置页面边框
*/
public void setDocumentBorders(WordprocessingMLPackage wordPackage, ObjectFactory factory, CTBorder top, CTBorder right, CTBorder bottom, CTBorder left) {
SectPr sectPr = getDocSectPr(wordPackage);
PgBorders pgBorders = sectPr.getPgBorders();
if (pgBorders == null) {
pgBorders = factory.createSectPrPgBorders();
sectPr.setPgBorders(pgBorders);
}
if (top != null) {
pgBorders.setTop(top);
}
if (right != null) {
pgBorders.setRight(right);
}
if (bottom != null) {
pgBorders.setBottom(bottom);
}
if (left != null) {
pgBorders.setLeft(left);
}
}
use of org.docx4j.wml.SectPr in project docx4j-template by vindell.
the class AddingPageNrToFooter method createFooterReference.
/**
* This method fetches the document final section properties, and adds a newly
* created footer reference to them.
*
* @param relationship
*/
public static void createFooterReference(Relationship relationship) {
List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
Aggregations