Free Support Forum - aspose.com

Aspose.word for Java 如何获取word文档中图片的坐标?

请问如何获取word文档中图片的坐标?我用api获取的都是0

@chenxf,

您可以使用以下Aspose.Words API Java代码来确定Word文档中图片的坐标:

Document doc = new Document("C:\\Temp\\Doc1.docx");

Shape shape = (Shape) doc.getFirstSection().getBody().getChildNodes(NodeType.SHAPE, true).get(0);

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

layoutEnumerator.setCurrent(layoutCollector.getEntity(shape));

// Left Top corner point
System.out.println("(" + layoutEnumerator.getRectangle().x + ", " + layoutEnumerator.getRectangle().y + ")");

// Right Bottom corner point
System.out.println("(" + (layoutEnumerator.getRectangle().x + layoutEnumerator.getRectangle().width) +
        ", " + (layoutEnumerator.getRectangle().y + layoutEnumerator.getRectangle().height) + ")");