by Madhuri92 » Wed Mar 13, 2019 3:07 pm
Hello Jason,
Thank you for replying. My current code for creating a document with an image looks as following:
public void addPicture(String path, float X, float Y, float width, float height) throws Exception {
File file = new File(path);
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(this.getWordprocessingMLPackage(), file);
Relationship rel = this.getWordprocessingMLPackage().getMainDocumentPart().addTargetPart(imagePart);
Map<String, String> styleMap = new HashMap<String, String>();
styleMap.put("position", "absolute"); styleMap.put("margin-left", (X +
"pt")); styleMap.put("margin-top", (Y + "pt")); styleMap.put("width", (width
+ "pt")); styleMap.put("height", height + "pt");
styleMap.put("mso-position-horizontal","absolute");
styleMap.put("mso-position-vertical","absolute");
styleMap.put("mso-position-horizontal-relative", "page");
styleMap.put("mso-position-vertical-relative", "page");
styleMap.put("visibility", "visible");
styleMap.put("mso-wrap-style","square");
Pict pict = createImageInline(rel, mapToString(":", ";", styleMap), "title");
JAXBElement<org.docx4j.wml.Pict> pictWrapped = wmlObjectFactory.createRPict(pict); ShapeImpl shape = new ShapeImpl();
shape.setStyle(mapToString(":", ";", styleMap));
shape.getEGShapeElements().add(pictWrapped);
JAXBElement<org.docx4j.vml.CTShape> shapeWrapped =
vmlObjectFactory.createShape(shape); // range.getContent().add(shapeWrapped);
this.getContent().add(shapeWrapped);
}
Above code works correctly to render an image. However, I want to set other image properties such as FlipH, FlipV and Rotation through code which is possible using CTTransform2D and CTShapeProperties, however I am not sure how to use them with above code.