Java Code Examples for org.docx4j.wml.ObjectFactory#createCTBackground()

The following examples show how to use org.docx4j.wml.ObjectFactory#createCTBackground() . 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 5 votes vote down vote up
/**
 * @Description: 设置页面背景色
 */
public static void setDocumentBackGround(WordprocessingMLPackage wordPackage, ObjectFactory factory, String color)
        throws Exception {
    MainDocumentPart mdp = wordPackage.getMainDocumentPart();
    CTBackground bkground = mdp.getContents().getBackground();
    if (StringUtils.isNotBlank(color)) {
        if (bkground == null) {
            bkground = factory.createCTBackground();
            bkground.setColor(color);
        }
        mdp.getContents().setBackground(bkground);
    }
}
 
Example 2
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @Description: 设置页面背景色
 */
public void setDocumentBackGround(WordprocessingMLPackage wordPackage,
        ObjectFactory factory, String color) throws Exception {
    MainDocumentPart mdp = wordPackage.getMainDocumentPart();
    CTBackground bkground = mdp.getContents().getBackground();
    if (StringUtils.isNotBlank(color)) {
        if (bkground == null) {
            bkground = factory.createCTBackground();
            bkground.setColor(color);
        }
        mdp.getContents().setBackground(bkground);
    }
}