Search in sources :

Example 36 with PPr

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

the class Docx4J_简单例子2 method getTextHdr.

public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception {
    Hdr hdr = factory.createHdr();
    P headP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    headP.getContent().add(run);
    PPr pPr = headP.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    PBdr pBdr = pPr.getPBdr();
    if (pBdr == null) {
        pBdr = factory.createPPrBasePBdr();
    }
    CTBorder value = new CTBorder();
    value.setVal(STBorder.SINGLE);
    value.setColor("000000");
    value.setSpace(new BigInteger("0"));
    value.setSz(new BigInteger("3"));
    pBdr.setBetween(value);
    pPr.setPBdr(pBdr);
    headP.setPPr(pPr);
    setParagraphSpacing(factory, headP, jcEnumeration, "0", "0");
    hdr.getContent().add(headP);
    hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration));
    return hdr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) Hdr(org.docx4j.wml.Hdr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Text(org.docx4j.wml.Text)

Example 37 with PPr

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

the class Docx4J_简单例子2 method addTableCell.

// 新增单元格
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) {
    Tc tableCell = factory.createTc();
    P p = factory.createP();
    setParagraphAlign(factory, p, jcEnumeration);
    Text t = factory.createText();
    t.setValue(content);
    R run = factory.createR();
    // 设置表格内容字体样式
    run.setRPr(rpr);
    TcPr tcPr = tableCell.getTcPr();
    if (tcPr == null) {
        tcPr = factory.createTcPr();
    }
    CTVerticalJc valign = factory.createCTVerticalJc();
    valign.setVal(STVerticalJc.CENTER);
    tcPr.setVAlign(valign);
    run.getContent().add(t);
    p.getContent().add(run);
    PPr ppr = p.getPPr();
    if (ppr == null) {
        ppr = factory.createPPr();
    }
    // 设置段后距离
    Spacing spacing = new Spacing();
    spacing.setAfter(new BigInteger("0"));
    spacing.setLineRule(STLineSpacingRule.AUTO);
    ppr.setSpacing(spacing);
    p.setPPr(ppr);
    tableCell.getContent().add(p);
    if (hasBgColor) {
        CTShd shd = tcPr.getShd();
        if (shd == null) {
            shd = factory.createCTShd();
        }
        shd.setColor("auto");
        shd.setFill(backgroudColor);
        tcPr.setShd(shd);
        tableCell.setTcPr(tcPr);
    }
    tableRow.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) Spacing(org.docx4j.wml.PPrBase.Spacing) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc)

Example 38 with PPr

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

the class Docx4J_简单例子2 method getTextFtr.

public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception {
    Ftr ftr = factory.createFtr();
    P footerP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    footerP.getContent().add(run);
    PPr pPr = footerP.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    footerP.setPPr(pPr);
    ftr.getContent().add(footerP);
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) Ftr(org.docx4j.wml.Ftr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Text(org.docx4j.wml.Text)

Example 39 with PPr

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

the class Docx4J_简单例子2 method createHeaderBlankP.

public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, JcEnumeration jcEnumeration) throws Exception {
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    PPr pPr = p.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    PBdr pBdr = pPr.getPBdr();
    if (pBdr == null) {
        pBdr = factory.createPPrBasePBdr();
    }
    CTBorder value = new CTBorder();
    value.setVal(STBorder.SINGLE);
    value.setColor("000000");
    value.setSpace(new BigInteger("0"));
    value.setSz(new BigInteger("3"));
    pBdr.setBetween(value);
    pPr.setPBdr(pBdr);
    p.setPPr(pPr);
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");
    return p;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger)

Example 40 with PPr

use of org.docx4j.wml.PPr 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)

Aggregations

PPr (org.docx4j.wml.PPr)48 Jc (org.docx4j.wml.Jc)29 R (org.docx4j.wml.R)23 P (org.docx4j.wml.P)22 CTVerticalJc (org.docx4j.wml.CTVerticalJc)21 STVerticalJc (org.docx4j.wml.STVerticalJc)20 BigInteger (java.math.BigInteger)17 Text (org.docx4j.wml.Text)14 PBdr (org.docx4j.wml.PPrBase.PBdr)10 CTBorder (org.docx4j.wml.CTBorder)9 RPr (org.docx4j.wml.RPr)6 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)5 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)5 Drawing (org.docx4j.wml.Drawing)5 Spacing (org.docx4j.wml.PPrBase.Spacing)5 Ftr (org.docx4j.wml.Ftr)4 ObjectFactory (org.docx4j.wml.ObjectFactory)4 ParaRPr (org.docx4j.wml.ParaRPr)4 Ind (org.docx4j.wml.PPrBase.Ind)3 Tc (org.docx4j.wml.Tc)3