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