Search in sources :

Example 6 with Inline

use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.

the class ComplexTable method newImage.

public static org.docx4j.wml.P newImage(WordprocessingMLPackage wordMLPackage, byte[] bytes, String filenameHint, String altText, int id1, int id2, long cx) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, cx);
    // Now add the inline in w:p/w:r/w:drawing
    org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
    org.docx4j.wml.P p = factory.createP();
    org.docx4j.wml.R run = factory.createR();
    p.getParagraphContent().add(run);
    org.docx4j.wml.Drawing drawing = factory.createDrawing();
    run.getRunContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return p;
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) ObjectFactory(org.docx4j.wml.ObjectFactory) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 7 with Inline

use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method newImage.

public P newImage(WordprocessingMLPackage wordMLPackage, byte[] bytes, String filenameHint, String altText, int id1, int id2, long cx) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, cx, false);
    // Now add the inline in w:p/w:r/w:drawing
    ObjectFactory factory = Context.getWmlObjectFactory();
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return p;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 8 with Inline

use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.

the class Write_Image method main.

public static void main(String[] args) throws Exception {
    WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
    mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
    mainDocumentPart.addParagraphOfText("Welcome To Baeldung");
    File image = new File("resources/image.png");
    byte[] fileContent = Files.readAllBytes(image.toPath());
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
    Inline inline = imagePart.createImageInline("Baeldung Image (filename hint)", "Alt Text", 1, 2, false);
    P Imageparagraph = addImageToParagraph(inline);
    mainDocumentPart.getContent().add(Imageparagraph);
    File exportFile = new File("output/welcome3.docx");
    wordPackage.save(exportFile);
    System.out.println("Done!");
}
Also used : P(org.docx4j.wml.P) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage) File(java.io.File)

Example 9 with Inline

use of org.docx4j.dml.wordprocessingDrawing.Inline in project docx4j-template by vindell.

the class Docx4J_例子2 method createImageParagraph.

// 段落中插入文字和图片
public P createImageParagraph(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P p, String fileName, String content, byte[] bytes, JcEnumeration jcEnumeration) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(fileName, "这是图片", 1, 2, false);
    Text text = factory.createText();
    text.setValue(content);
    text.setSpace("preserve");
    R run = factory.createR();
    p.getContent().add(run);
    run.getContent().add(text);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    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);
    p.setPPr(pPr);
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    return p;
}
Also used : Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Text(org.docx4j.wml.Text) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 10 with Inline

use of org.docx4j.dml.wordprocessingDrawing.Inline in project docx4j-template by vindell.

the class Docx4J_简单例子2 method newImage.

public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, JcEnumeration jcEnumeration) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, sourcePart, bytes);
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false);
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    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);
    p.setPPr(pPr);
    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);
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");
    return p;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) 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) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Aggregations

Inline (org.docx4j.dml.wordprocessingDrawing.Inline)26 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)16 P (org.docx4j.wml.P)10 R (org.docx4j.wml.R)10 Test (org.junit.Test)10 Drawing (org.docx4j.wml.Drawing)9 Jc (org.docx4j.wml.Jc)5 PPr (org.docx4j.wml.PPr)5 CTVerticalJc (org.docx4j.wml.CTVerticalJc)4 ObjectFactory (org.docx4j.wml.ObjectFactory)4 STVerticalJc (org.docx4j.wml.STVerticalJc)4 Text (org.docx4j.wml.Text)4 File (java.io.File)3 BigInteger (java.math.BigInteger)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)2 CTBorder (org.docx4j.wml.CTBorder)2 PBdr (org.docx4j.wml.PPrBase.PBdr)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1