Table Parsing Question - how to determine left indent?


I’m trying to implement a Visitor that can print out the position of the left line of each cell in a table. I would like it to be able to handle any table. However, I am having issues because I am not able to determine the indentation/position of the first cell since it may be indented differently relative to the other rows.

I have attached an example document. Does anyone know how I may use the aspose API to correctly determine the position/indentation of the first line in each row? I would presumably be able to easily compute the remaining lines in each cell given the I can easily get the next line by summing up the current cell’s width as follows:
double currentPosition = ConvertUtil.pointToInch(cell.getCellFormat().getWidth()).

I thought it would be possible for me to determine the left indent of the each row by calling:
ConvertUtil.pointToInch(row.getRowFormat().getLeftIndent()) inside of visitRowStart():

public int visitRowStart(Row row) throws Exception {
    rowSumInch = ConvertUtil.pointToInch(row.getRowFormat().getLeftIndent());
    System.out.printf("New Row%n\tLeftIndent: %f%n", rowSumInch);
    return super.visitRowStart(row);

However, it appears that this returns the same value for both rows in my example table:
LeftIndent: 0.387500
LeftIndent: 0.387500

Clearly from the example we can see that the indentation of each row is different.

I am adding my example visitor that I am using that includes all of the code that I am using to investigate this.


Hi Chase,

Thanks for your inquiry.You can achieve your requirements using Aspose.Words.Layout class. Aspose.Words uses our own Rendering Engine to layout documents into pages. The Aspose.Words.Layout namespace provides
classes that allow to access information such as on what page and where
on a page particular document elements are positioned, when the document
is formatted into pages. Please read about LayoutCollector and
LayoutEnumerator from here:

Please use following code example to get the position of first paragraph of first row. Hope this helps you.

Document doc = new Document(MyDir + "complexTest.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
for (Row row : (Iterable)doc.getChildNodes(NodeType.ROW, true))
    Object renderObject = layoutCollector.getEntity(row.getFirstCell().getFirstParagraph());
    System.out.println("X :" + layoutEnumerator.getRectangle().getY() + " - Y: " + layoutEnumerator.getRectangle().getX());

Thank you Tahir,

This should be what I need for now…

I will post back if there are any issues.