Java Code Examples for org.docx4j.wml.SectPr#setPgMar()

The following examples show how to use org.docx4j.wml.SectPr#setPgMar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description:设置页边距
 */
public static 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));
    }
}
 
Example 2
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @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));
    }
}
 
Example 3
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
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();  
    }  
}