Hi,
I have written some code based on your samples to output the absolute x and y position of row text in a word docs. The code is shown below. The issue I am facing is that the y position output for the row text is incorrect
import com.aspose.words.Document;
import com.aspose.words.LayoutCollector;
import com.aspose.words.LayoutEnumerator;
import com.aspose.words.Node;
import com.aspose.words.NodeCollection;
import com.aspose.words.NodeType;
import com.aspose.words.Row;
import com.aspose.words.Section;
import com.aspose.words.Shape;
public class asposeMatcher {
public static LayoutCollector collector;
public static LayoutEnumerator enumerator;
public static void main(String[] args) throws Exception {
//final Document doc = new Document(System.getProperty("user.dir") + "/first_page.docx");
final Document doc = new Document(System.getProperty("user.dir") + "/current_settings.docx");
collector = new LayoutCollector(doc);
enumerator = new LayoutEnumerator(doc);
Section[] secColl = doc.getSections().toArray();
for (Section section: secColl)
{
System.out.println(containsShapesAndTable(section));
if (containsShapesAndTable(section))
{
outputShapesAndRowPosititions(section);
}
}
}
public static boolean containsShapesAndTable(Section section)
{
NodeCollection ndPara = section.getChildNodes(NodeType.PARAGRAPH, true);
NodeCollection ndShape = section.getChildNodes(NodeType.SHAPE, true);
NodeCollection ndTable = section.getChildNodes(NodeType.TABLE, true);
//System.out.println(ndPara.getCount());
System.out.println(ndShape.getCount());
System.out.println(ndTable.getCount());
if (ndPara.getCount() > 0 && ndTable.getCount() > 0)
{
return true;
}
return false;
}
public static void outputShapesAndRowPosititions(Section section)
{
NodeCollection ndShapes = section.getChildNodes(NodeType.SHAPE, true);
NodeCollection ndRows = section.getChildNodes(NodeType.ROW, true);
//shapes
for (Object ndShape : ndShapes)
{
Shape nodeShape = (Shape) ndShape;
try {
outputPositionInfo ((Node) ndShape);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(nodeShape.getText());
}
//rows
for (Object ndRow : ndRows)
{
Row nodeRow = (Row) ndRow;
try {
outputPositionInfo ((Node) ndRow);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(nodeRow.getText());
}
}
public static void outputPositionInfo (Node objToCheck) throws Exception {
enumerator.setCurrent(collector.getEntity(objToCheck));
String left = String.format("%.2f", enumerator.getRectangle().getX());
String top = String.format("%.2f", enumerator.getRectangle().getY());
String width = String.format("%.2f", enumerator.getRectangle().getWidth());
String height = String.format("%.2f", enumerator.getRectangle().getHeight());
System.out.print("[(x, y) = (" + left + ", " + top + ")]");
System.out.println(" AND [(width, height) = (" + width + ", " + height + ")]");
}
}