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);
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
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);
}
Aggregations