Search in sources :

Example 51 with P

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

the class DocxBuilder method addImage.

public void addImage(byte[] imageBytes) throws Exception {
    BinaryPartAbstractImage.setDensity(600);
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, imageBytes);
    Inline inline = imagePart.createImageInline(null, null, 0, 1, false);
    ObjectFactory factory = Context.getWmlObjectFactory();
    P imgP = factory.createP();
    R imgRun = factory.createR();
    imgP.getContent().add(imgRun);
    Drawing drawing = factory.createDrawing();
    imgRun.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    getMdp().addObject(imgP);
}
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 52 with P

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

the class DocxBuilder method addNumberedList.

public void addNumberedList(List<String> list) throws Exception {
    if (numberingNum == null) {
        numberingNum = getNdp().addAbstractListNumberingDefinition((Numbering.AbstractNum) XmlUtils.unmarshalString(getFragment("numbering")));
        numberingNumId = numberingNum.getNumId();
    } else {
        numberingNumId = BigInteger.valueOf(ndp.restart(numberingNumId.longValue(), 0, 1));
    }
    for (String item : list) {
        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);
        // create and add <w:numPr>
        NumPr numPr = factory.createPPrBaseNumPr();
        listPpr.setNumPr(numPr);
        // the <w:ilvl> element
        Ilvl ilvlElement = factory.createPPrBaseNumPrIlvl();
        numPr.setIlvl(ilvlElement);
        ilvlElement.setVal(BigInteger.valueOf(0));
        // The <w:numId> element
        NumId numIdElement = factory.createPPrBaseNumPrNumId();
        numPr.setNumId(numIdElement);
        numIdElement.setVal(numberingNumId);
        getMdp().addObject(listP);
    }
}
Also used : P(org.docx4j.wml.P) NumId(org.docx4j.wml.PPrBase.NumPr.NumId) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) ObjectFactory(org.docx4j.wml.ObjectFactory) NumPr(org.docx4j.wml.PPrBase.NumPr) Text(org.docx4j.wml.Text) Ilvl(org.docx4j.wml.PPrBase.NumPr.Ilvl)

Example 53 with P

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

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

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

the class HyperlinkTest method testHrefNoNameNoContent.

@Test
public void testHrefNoNameNoContent() throws Docx4JException {
    String name = null;
    String href = "http://www.google.com";
    String content = null;
    List<Object> objects = fromXHTML(a(href, name, content));
    P p = (P) objects.get(0);
    // No link
    assertEquals(p.getContent().get(0).getClass(), R.class);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

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