use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.
the class ImageAddTest method testSizeNoWidth.
@Test
public void testSizeNoWidth() throws Exception {
Inline inline = getInline("<div><img src='" + PNG_IMAGE_DATA + "' height='20pt' /></div>");
Assert.assertTrue(Math.round(inline.getExtent().getCx() / 10) == // +/- a few EMU
Math.round(inline.getExtent().getCy() / 10));
}
use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.
the class ImageAddTest method testSizeNoHeight.
@Test
public void testSizeNoHeight() throws Exception {
Inline inline = getInline("<div><img src='" + PNG_IMAGE_DATA + "' width='20pt' /></div>");
Assert.assertTrue(Math.round(inline.getExtent().getCx() / 10) == // +/- a few EMU
Math.round(inline.getExtent().getCy() / 10));
}
use of org.docx4j.dml.wordprocessingDrawing.Inline in project Java-Tutorial by gpcodervn.
the class ImageResizeTest method testCmAgainstPx.
@Test
public void testCmAgainstPx() throws Exception {
Inline inline1 = getInline("<div><img src='" + PNG_IMAGE_DATA + "' height='20px' width='40px'/></div>");
Inline inline2 = getInline("<div><img src='" + PNG_IMAGE_DATA + "' height='20cm' width='40cm'/></div>");
Assert.assertTrue(inline2.getExtent().getCx() / inline1.getExtent().getCx() > 10);
Assert.assertTrue(inline2.getExtent().getCx() / inline1.getExtent().getCy() > 10);
}
use of org.docx4j.dml.wordprocessingDrawing.Inline in project tutorials by eugenp.
the class Docx4jExample method createDocumentPackage.
void createDocumentPackage(String outputPath, String imagePath) throws Exception {
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
mainDocumentPart.addParagraphOfText("Welcome To Baeldung!");
ObjectFactory factory = Context.getWmlObjectFactory();
P p = factory.createP();
R r = factory.createR();
Text t = factory.createText();
t.setValue("Welcome To Baeldung");
r.getContent().add(t);
p.getContent().add(r);
RPr rpr = factory.createRPr();
BooleanDefaultTrue b = new BooleanDefaultTrue();
rpr.setB(b);
rpr.setI(b);
rpr.setCaps(b);
Color red = factory.createColor();
red.setVal("green");
rpr.setColor(red);
r.setRPr(rpr);
mainDocumentPart.getContent().add(p);
File image = new File(imagePath);
byte[] fileContent = Files.readAllBytes(image.toPath());
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
Inline inline = imagePart.createImageInline("Baeldung Image", "Alt Text", 1, 2, false);
P Imageparagraph = addImageToParagraph(inline);
mainDocumentPart.getContent().add(Imageparagraph);
int writableWidthTwips = wordPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
int columnNumber = 3;
Tbl tbl = TblFactory.createTable(3, 3, writableWidthTwips / columnNumber);
List<Object> rows = tbl.getContent();
for (Object row : rows) {
Tr tr = (Tr) row;
List<Object> cells = tr.getContent();
for (Object cell : cells) {
Tc td = (Tc) cell;
td.getContent().add(p);
}
}
mainDocumentPart.getContent().add(tbl);
File exportFile = new File(outputPath);
wordPackage.save(exportFile);
}
use of org.docx4j.dml.wordprocessingDrawing.Inline 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