Determining Image Overlap in a Document

Hi Team,

The document contains three images. The third image overlaps with the first and second images. How to determine if the figures overlap or not? If possible, please share the source code.

Docuement: Fig0001.docx (24.6 KB)

Regards,
Mahi

@Mahi39 You can use LayoutCollector and LayoutEnumerator to calculate actual shape bounds and then determine whether they overlap or not. To achieve this your can calculate actual shape bounds and then checking whether the calculated bounds overlaps. For example see the following code:

Document doc = new Document("C:\\Temp\\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

// Check whether the 2nd shape overlap the 1st shape overlap.
Shape s1 = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Shape s2 = (Shape)doc.getChild(NodeType.SHAPE, 1, true);

enumerator.setCurrent(collector.getEntity(s1));
Rectangle2D s1Rect = enumerator.getRectangle();

enumerator.setCurrent(collector.getEntity(s2));
Rectangle2D s2Rect = enumerator.getRectangle();

// Returns true if shapes overlap.
System.out.println(s1Rect.intersects(s2Rect));