Search in sources :

Example 6 with Drawing

use of org.docx4j.wml.Drawing in project Java-Tutorial by gpcodervn.

the class ContainerParseTest method testParagraphInTableCellLayout.

@Test
public void testParagraphInTableCellLayout() throws Exception {
    String html = "<table><tbody><tr>" + "<td><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/>" + "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>" + "<img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></td></tr></tbody></table>";
    List<Object> tConvert = convert(html);
    Assert.assertTrue(tConvert.size() == 1);
    for (Object t : tConvert) {
        Assert.assertTrue(t instanceof Tbl);
        Tbl table = (Tbl) t;
        List<Object> convert = ((Tc) ((Tr) table.getContent().get(0)).getContent().get(0)).getContent();
        Assert.assertTrue(convert.size() == 3);
        for (Object o : convert) {
            Assert.assertTrue(o instanceof P);
            P paragraph = (P) o;
            List<Object> content = paragraph.getContent();
            Assert.assertTrue(content.size() == 2);
            for (Object child : content) {
                Assert.assertTrue(child instanceof R);
                R run = ((R) child);
                List<Object> rContent = run.getContent();
                Assert.assertTrue(rContent.size() == 1);
                Assert.assertTrue(rContent.get(0) instanceof Drawing);
            }
        }
    }
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc) Test(org.junit.Test)

Example 7 with Drawing

use of org.docx4j.wml.Drawing in project Java-Tutorial by gpcodervn.

the class ContainerParseTest method testParagraphInParagraphLayout.

@Test
public void testParagraphInParagraphLayout() throws Exception {
    String html = "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/>" + "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>" + "<img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>";
    List<Object> convert = convert(html);
    Assert.assertTrue(convert.size() == 3);
    for (Object o : convert) {
        Assert.assertTrue(o instanceof P);
        P paragraph = (P) o;
        List<Object> content = paragraph.getContent();
        Assert.assertTrue(content.size() == 2);
        for (Object child : content) {
            Assert.assertTrue(child instanceof R);
            R run = ((R) child);
            List<Object> rContent = run.getContent();
            Assert.assertTrue(rContent.size() == 1);
            Assert.assertTrue(rContent.get(0) instanceof Drawing);
        }
    }
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) Test(org.junit.Test)

Example 8 with Drawing

use of org.docx4j.wml.Drawing in project Java-Tutorial by gpcodervn.

the class Write_Image method addImageToParagraph.

private static P addImageToParagraph(Inline inline) {
    ObjectFactory factory = new ObjectFactory();
    P p = factory.createP();
    R r = factory.createR();
    p.getContent().add(r);
    Drawing drawing = factory.createDrawing();
    r.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)

Example 9 with Drawing

use of org.docx4j.wml.Drawing in project tutorials by eugenp.

the class Docx4jExample method addImageToParagraph.

private static P addImageToParagraph(Inline inline) {
    ObjectFactory factory = new ObjectFactory();
    P p = factory.createP();
    R r = factory.createR();
    p.getContent().add(r);
    Drawing drawing = factory.createDrawing();
    r.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)

Example 10 with Drawing

use of org.docx4j.wml.Drawing 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, boolean isUnderLine, String underLineSize, 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);
    if (isUnderLine) {
        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(underLineSize));
        pBdr.setBetween(value);
        pPr.setPBdr(pBdr);
    }
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    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

Drawing (org.docx4j.wml.Drawing)17 R (org.docx4j.wml.R)17 P (org.docx4j.wml.P)14 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)9 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)9 ObjectFactory (org.docx4j.wml.ObjectFactory)8 Jc (org.docx4j.wml.Jc)5 PPr (org.docx4j.wml.PPr)5 CTVerticalJc (org.docx4j.wml.CTVerticalJc)4 STVerticalJc (org.docx4j.wml.STVerticalJc)4 Text (org.docx4j.wml.Text)3 BigInteger (java.math.BigInteger)2 CTBorder (org.docx4j.wml.CTBorder)2 PBdr (org.docx4j.wml.PPrBase.PBdr)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Tbl (org.docx4j.wml.Tbl)1 Tc (org.docx4j.wml.Tc)1 Tr (org.docx4j.wml.Tr)1