Search in sources :

Example 96 with P

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

the class AddingAnInlineImage method addInlineImageToParagraph.

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

Example 97 with P

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

the class AddingAnInlineImageToTable method addInlineImageToParagraph.

/**
 *  向新的段落中添加内联图片并返回这个段落.
 *  这个方法与前面例子中的方法没有区别.
 * @param inline
 * @return
 */
private 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 98 with P

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

the class AddingTableOfContent method addTableOfContent.

/**
 *  将目录表添加到文档.
 *
 *  首先我们创建段落. 然后添加标记域开始的指示符, 然后添加域内容(真正的目录表), 接着添加域
 *  结束的指示符. 最后将段落添加到给定文档的JAXB元素中.
 *
 *  @param documentPart
 */
private static void addTableOfContent(MainDocumentPart documentPart) {
    P paragraph = factory.createP();
    addFieldBegin(paragraph);
    addTableOfContentField(paragraph);
    addFieldEnd(paragraph);
    documentPart.getJaxbElement().getBody().getContent().add(paragraph);
}
Also used : P(org.docx4j.wml.P)

Example 99 with P

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

Example 100 with P

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

the class AddingAPageBreak method addPageBreak.

/**
 * 向文档添加一个换行符
 */
private static void addPageBreak() {
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    Br breakObj = new Br();
    breakObj.setType(STBrType.PAGE);
    P paragraph = factory.createP();
    paragraph.getContent().add(breakObj);
    documentPart.getJaxbElement().getBody().getContent().add(paragraph);
}
Also used : Br(org.docx4j.wml.Br) P(org.docx4j.wml.P) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)

Aggregations

P (org.docx4j.wml.P)101 R (org.docx4j.wml.R)58 Text (org.docx4j.wml.Text)32 Test (org.junit.Test)23 PPr (org.docx4j.wml.PPr)22 RPr (org.docx4j.wml.RPr)21 ObjectFactory (org.docx4j.wml.ObjectFactory)18 Jc (org.docx4j.wml.Jc)16 BigInteger (java.math.BigInteger)14 CTVerticalJc (org.docx4j.wml.CTVerticalJc)14 Drawing (org.docx4j.wml.Drawing)14 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)13 STVerticalJc (org.docx4j.wml.STVerticalJc)11 Tc (org.docx4j.wml.Tc)11 File (java.io.File)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tbl (org.docx4j.wml.Tbl)10 Tr (org.docx4j.wml.Tr)10 Br (org.docx4j.wml.Br)9