Search in sources :

Example 26 with ObjectFactory

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

the class WmlElementUtils method addInlineImageToParagraph.

/**
 *  创建一个对象工厂并用它创建一个段落和一个可运行块R.
 *  然后将可运行块添加到段落中. 接下来创建一个图画并将其添加到可运行块R中. 最后我们将内联
 *  对象添加到图画中并返回段落对象.
 *
 * @param   inline 包含图片的内联对象.
 * @return  包含图片的段落
 */
public static P addInlineImageToParagraph(Inline inline) {
    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)

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