Search in sources :

Example 1 with SectPr

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();
    }
}
Also used : PageDimensions(org.docx4j.model.structure.PageDimensions) PgMar(org.docx4j.wml.SectPr.PgMar) SectPr(org.docx4j.wml.SectPr) Body(org.docx4j.wml.Body) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 2 with SectPr

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);
    }
}
Also used : TextDirection(org.docx4j.wml.TextDirection) SectPr(org.docx4j.wml.SectPr)

Example 3 with SectPr

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);
    }
}
Also used : SectPr(org.docx4j.wml.SectPr) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Example 4 with SectPr

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);
    }
}
Also used : SectPr(org.docx4j.wml.SectPr) PgBorders(org.docx4j.wml.SectPr.PgBorders)

Example 5 with SectPr

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);
}
Also used : SectionWrapper(org.docx4j.model.structure.SectionWrapper) FooterReference(org.docx4j.wml.FooterReference) SectPr(org.docx4j.wml.SectPr)

Aggregations

SectPr (org.docx4j.wml.SectPr)18 SectionWrapper (org.docx4j.model.structure.SectionWrapper)8 FooterReference (org.docx4j.wml.FooterReference)5 BigInteger (java.math.BigInteger)4 HeaderReference (org.docx4j.wml.HeaderReference)3 PgMar (org.docx4j.wml.SectPr.PgMar)3 PageDimensions (org.docx4j.model.structure.PageDimensions)2 Body (org.docx4j.wml.Body)2 PgSz (org.docx4j.wml.SectPr.PgSz)2 Type (org.docx4j.wml.SectPr.Type)2 TextDirection (org.docx4j.wml.TextDirection)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)1 CTLineNumber (org.docx4j.wml.CTLineNumber)1 CTVerticalJc (org.docx4j.wml.CTVerticalJc)1 P (org.docx4j.wml.P)1 PPr (org.docx4j.wml.PPr)1 RPr (org.docx4j.wml.RPr)1 STBrType (org.docx4j.wml.STBrType)1