Search in sources :

Example 6 with ObjectFactory

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

the class ParagraphUtils method addInlineImageToParagraph.

/**
 *  向新的段落中添加内联图片并返回这个段落.
 *  这个方法与前面例子中的方法没有区别.
 * @param inline
 * @return
 */
public static P addInlineImageToParagraph(Inline inline) {
    // Now add the in-line image to a paragraph
    ObjectFactory factory = new ObjectFactory();
    P paragraph = factory.createP();
    R run = factory.createR();
    paragraph.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return paragraph;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory)

Example 7 with ObjectFactory

use of org.docx4j.wml.ObjectFactory in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method createBoldParagraph.

public P createBoldParagraph(String style, String text) {
    ObjectFactory factory = Context.getWmlObjectFactory();
    RPr rprDoc = factory.createRPr();
    BooleanDefaultTrue b = new BooleanDefaultTrue();
    b.setVal(true);
    rprDoc.setB(b);
    P pDoc = getMdp().createStyledParagraphOfText(style, text);
    R rDoc = (R) pDoc.getContent().get(0);
    rDoc.setRPr(rprDoc);
    return pDoc;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) RPr(org.docx4j.wml.RPr) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 8 with ObjectFactory

use of org.docx4j.wml.ObjectFactory in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method addBulletList.

public void addBulletList(List<String> items) throws Exception {
    if (bulletNum == null) {
        bulletNum = getNdp().addAbstractListNumberingDefinition((Numbering.AbstractNum) XmlUtils.unmarshalString(getFragment("bulletNumbering")));
        bulletNumId = bulletNum.getNumId();
    } else {
        bulletNumId = BigInteger.valueOf(ndp.restart(bulletNumId.longValue(), 0, 1));
    }
    for (String item : items) {
        ObjectFactory factory = Context.getWmlObjectFactory();
        P listP = factory.createP();
        Text t = factory.createText();
        t.setValue(item);
        R listRun = factory.createR();
        listRun.getContent().add(t);
        listP.getContent().add(listRun);
        PPr listPpr = factory.createPPr();
        listP.setPPr(listPpr);
        listPpr.setNumPr(createBulletListNumPr());
        PStyle pStyle = factory.createPPrBasePStyle();
        pStyle.setVal("ListParagraph");
        listPpr.setPStyle(pStyle);
        getMdp().addObject(listP);
    }
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) ObjectFactory(org.docx4j.wml.ObjectFactory) Text(org.docx4j.wml.Text) PStyle(org.docx4j.wml.PPrBase.PStyle)

Example 9 with ObjectFactory

use of org.docx4j.wml.ObjectFactory in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method addBoldParagraph.

public P addBoldParagraph(String text) {
    ObjectFactory factory = Context.getWmlObjectFactory();
    RPr rprDoc = factory.createRPr();
    BooleanDefaultTrue b = new BooleanDefaultTrue();
    b.setVal(true);
    rprDoc.setB(b);
    P pDoc = getMdp().addParagraphOfText(text);
    R rDoc = (R) pDoc.getContent().get(0);
    rDoc.setRPr(rprDoc);
    return pDoc;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) RPr(org.docx4j.wml.RPr) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 10 with ObjectFactory

use of org.docx4j.wml.ObjectFactory in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method createParagraph.

public P createParagraph(String text, int fontSize, boolean bold) {
    ObjectFactory factory = Context.getWmlObjectFactory();
    RPr rprDoc = factory.createRPr();
    if (fontSize != 0) {
        HpsMeasure size = new HpsMeasure();
        size.setVal(BigInteger.valueOf(fontSize * 2));
        rprDoc.setSz(size);
    }
    if (bold) {
        BooleanDefaultTrue b = new BooleanDefaultTrue();
        b.setVal(true);
        rprDoc.setB(b);
    }
    P pDoc = getMdp().createParagraphOfText(text);
    R rDoc = (R) pDoc.getContent().get(0);
    rDoc.setRPr(rprDoc);
    return pDoc;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) RPr(org.docx4j.wml.RPr) HpsMeasure(org.docx4j.wml.HpsMeasure) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Aggregations

ObjectFactory (org.docx4j.wml.ObjectFactory)26 P (org.docx4j.wml.P)18 R (org.docx4j.wml.R)17 File (java.io.File)8 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)8 Drawing (org.docx4j.wml.Drawing)8 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)7 Text (org.docx4j.wml.Text)6 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)5 RPr (org.docx4j.wml.RPr)5 Relationship (org.docx4j.relationships.Relationship)4 PPr (org.docx4j.wml.PPr)4 Tbl (org.docx4j.wml.Tbl)4 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)3 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)3 Tc (org.docx4j.wml.Tc)3 Tr (org.docx4j.wml.Tr)3 Color (org.docx4j.wml.Color)2 Hyperlink (org.docx4j.wml.P.Hyperlink)2 NumPr (org.docx4j.wml.PPrBase.NumPr)2