Get bytes from Shape

Hi there,


How can I convert the Shape in the attached document to a PNG and get the bytes for it?

Shape.getImageData().getImageBytes() returns null.

Hi Alex,


Thanks for your inquiry. Sure, you can render shapes in your document into images and saves into a stream or to disk by using the following code snippet:
Document doc = new Document(“C:\Temp\testShape.docx”);

int i = 0;
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
ShapeRenderer r = shape.getShapeRenderer();

ImageSaveOptions imageOptions <font color="BLUE">=</font> <font color="RED"><b>new</b></font> ImageSaveOptions<font color="BLUE"><b>(</b></font>SaveFormat<font color="BLUE"><b>.</b></font>PNG<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
r<font color="BLUE"><b>.</b></font>save<font color="BLUE"><b>(</b></font><font color="PURPLE">"C:\\temp\\img"</font> <font color="BLUE">+</font> i <font color="BLUE">+</font> <font color="PURPLE">".png"</font><font color="BLUE"><b>,</b></font> imageOptions<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
i<font color="BLUE"><font color="BLUE">+</font><font color="BLUE">+</font></font><font color="BLUE"><b>;</b></font>

}

I hope, this helps.

Best regards,