Search in sources :

Example 31 with RPr

use of org.docx4j.wml.RPr in project docx4j-template by vindell.

the class Docx4j_Helper method testDocx4jSetPageSize.

public void testDocx4jSetPageSize() throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    String titleStr = "静夜思    李白";
    String str = "床前明月光,疑似地上霜。";
    String str2 = "举头望明月,低头思故乡。";
    P p = Docx4j_Helper.factory.createP();
    String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
    RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
    setParagraphContent(p, rpr, titleStr);
    mdp.addObject(p);
    p = Docx4j_Helper.factory.createP();
    setParagraphContent(p, rpr, str);
    mdp.addObject(p);
    p = Docx4j_Helper.factory.createP();
    PPr pPr = Docx4j_Helper.factory.createPPr();
    // 设置文字方向
    SectPr sectPr = Docx4j_Helper.factory.createSectPr();
    TextDirection textDirect = Docx4j_Helper.factory.createTextDirection();
    // 文字方向:垂直方向从右往左
    textDirect.setVal("tbRl");
    sectPr.setTextDirection(textDirect);
    Type sectType = Docx4j_Helper.factory.createSectPrType();
    // 下一页
    sectType.setVal("nextPage");
    sectPr.setType(sectType);
    // 设置页面大小
    PgSz pgSz = Docx4j_Helper.factory.createSectPrPgSz();
    pgSz.setW(new BigInteger("8335"));
    pgSz.setH(new BigInteger("11850"));
    sectPr.setPgSz(pgSz);
    pPr.setSectPr(sectPr);
    p.setPPr(pPr);
    setParagraphContent(p, rpr, str2);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, titleStr);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, str);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, str2);
    mdp.addObject(p);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
Also used : P(org.docx4j.wml.P) Type(org.docx4j.wml.SectPr.Type) PPr(org.docx4j.wml.PPr) TextDirection(org.docx4j.wml.TextDirection) RPr(org.docx4j.wml.RPr) SectPr(org.docx4j.wml.SectPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) BigInteger(java.math.BigInteger) PgSz(org.docx4j.wml.SectPr.PgSz) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage)

Example 32 with RPr

use of org.docx4j.wml.RPr in project docx4j-template by vindell.

the class Docx4jStyle_S3 method addCellStyle.

public void addCellStyle(ObjectFactory factory, Tc tableCell, String content, Docx4jStyle_S3 style) {
    if (style != null) {
        P paragraph = factory.createP();
        Text text = factory.createText();
        text.setValue(content);
        R run = factory.createR();
        run.getContent().add(text);
        paragraph.getContent().add(run);
        setHorizontalAlignment(paragraph, style.getHorizAlignment());
        RPr runProperties = factory.createRPr();
        if (style.isBold()) {
            addBoldStyle(runProperties);
        }
        if (style.isItalic()) {
            addItalicStyle(runProperties);
        }
        if (style.isUnderline()) {
            addUnderlineStyle(runProperties);
        }
        setFontSize(runProperties, style.getFontSize());
        setFontColor(runProperties, style.getFontColor());
        setFontFamily(runProperties, style.getCnFontFamily(), style.getEnFontFamily());
        setCellMargins(tableCell, style.getTop(), style.getRight(), style.getBottom(), style.getLeft());
        setCellColor(tableCell, style.getBackground());
        setVerticalAlignment(tableCell, style.getVerticalAlignment());
        setCellBorders(tableCell, style.isBorderTop(), style.isBorderRight(), style.isBorderBottom(), style.isBorderLeft());
        run.setRPr(runProperties);
        tableCell.getContent().add(paragraph);
    }
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) RPr(org.docx4j.wml.RPr) Text(org.docx4j.wml.Text)

Example 33 with RPr

use of org.docx4j.wml.RPr in project docx4j-template by vindell.

the class Docx4j_工具类_S3_Test method setTcHidden.

/**
 * @Description: 隐藏单元格内容
 */
public void setTcHidden(Tc tc, boolean hidden) {
    List<P> pList = getTcAllP(tc);
    for (P p : pList) {
        PPr ppr = getPPr(p);
        List<Object> objRList = getAllElementFromObject(p, R.class);
        if (objRList == null) {
            continue;
        }
        for (Object objR : objRList) {
            if (objR instanceof R) {
                R r = (R) objR;
                RPr rpr = getRPr(r);
                setRPrVanishStyle(rpr, hidden);
            }
        }
        setParaVanish(ppr, hidden);
    }
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) RPr(org.docx4j.wml.RPr) ParaRPr(org.docx4j.wml.ParaRPr)

Example 34 with RPr

use of org.docx4j.wml.RPr in project docx4j-template by vindell.

the class WordprocessingMLPackageRender method addStyling.

/**
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
 *  到其中. 随后我们将运行块R添加到段落内容中.
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
 */
public void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {
    P paragraph = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    paragraph.getContent().add(run);
    RPr runProperties = factory.createRPr();
    if (bold) {
        addBoldStyle(runProperties);
    }
    if (fontSize != null && !fontSize.isEmpty()) {
        setFontSize(runProperties, fontSize);
    }
    run.setRPr(runProperties);
    tableCell.getContent().add(paragraph);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) RPr(org.docx4j.wml.RPr) Text(org.docx4j.wml.Text)

Example 35 with RPr

use of org.docx4j.wml.RPr in project docx4j-template by vindell.

the class ChangingTheStyleSheet method alterNormalStyle.

/**
 *  First we create a run properties object as we want to remove nearly all of
 *  the existing styling. Then we change the font and font size and set the
 *  run properties on the given style. As in previous examples, the font size
 *  is defined to be in half-point size.
 */
private static void alterNormalStyle(Style style) {
    // we want to change (or remove) almost all the run properties of the
    // normal style, so we create a new one.
    RPr rpr = new RPr();
    changeFontToArial(rpr);
    changeFontSize(rpr, 20);
    style.setRPr(rpr);
}
Also used : RPr(org.docx4j.wml.RPr)

Aggregations

RPr (org.docx4j.wml.RPr)37 P (org.docx4j.wml.P)21 R (org.docx4j.wml.R)19 Text (org.docx4j.wml.Text)12 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)9 BigInteger (java.math.BigInteger)8 ParaRPr (org.docx4j.wml.ParaRPr)8 U (org.docx4j.wml.U)7 Color (org.docx4j.wml.Color)6 PPr (org.docx4j.wml.PPr)6 RFonts (org.docx4j.wml.RFonts)6 Tbl (org.docx4j.wml.Tbl)6 Tr (org.docx4j.wml.Tr)6 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)5 HpsMeasure (org.docx4j.wml.HpsMeasure)5 ObjectFactory (org.docx4j.wml.ObjectFactory)5 File (java.io.File)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)4 STHint (org.docx4j.wml.STHint)4 Ftr (org.docx4j.wml.Ftr)3