Search in sources :

Example 46 with R

use of org.docx4j.wml.R 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 47 with R

use of org.docx4j.wml.R 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 48 with R

use of org.docx4j.wml.R 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 49 with R

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

the class HyperlinkTest method testFollowingSpan.

private void testFollowingSpan(List<Object> contents, String followingSpanContent) {
    R lastRun = null;
    for (Object o : contents) {
        o = XmlUtils.unwrap(o);
        if (o instanceof R) {
            lastRun = (R) o;
        }
    }
    testContent(lastRun, R.class, followingSpanContent);
}
Also used : R(org.docx4j.wml.R)

Example 50 with R

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

the class HyperlinkTest method testFollowingP.

private void testFollowingP(P p, String followingPContent) {
    System.out.println(XmlUtils.marshaltoString(p, true, true));
    R r = (R) p.getContent().get(0);
    testContent(r, R.class, followingPContent);
}
Also used : R(org.docx4j.wml.R)

Aggregations

R (org.docx4j.wml.R)93 P (org.docx4j.wml.P)58 Text (org.docx4j.wml.Text)53 PPr (org.docx4j.wml.PPr)23 Jc (org.docx4j.wml.Jc)18 RPr (org.docx4j.wml.RPr)18 Drawing (org.docx4j.wml.Drawing)17 ObjectFactory (org.docx4j.wml.ObjectFactory)17 CTVerticalJc (org.docx4j.wml.CTVerticalJc)16 STVerticalJc (org.docx4j.wml.STVerticalJc)13 FldChar (org.docx4j.wml.FldChar)11 BigInteger (java.math.BigInteger)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tc (org.docx4j.wml.Tc)10 CTBorder (org.docx4j.wml.CTBorder)8 PBdr (org.docx4j.wml.PPrBase.PBdr)8 Ftr (org.docx4j.wml.Ftr)7 File (java.io.File)6 Tr (org.docx4j.wml.Tr)6