Hi all,
I am traversing a table and I need to find start and end coordinates of all the rows separately for each row.Flow of my code is I am traversing over each row and creating a bookmark start and end at that row position. Then I am initialising layoutCollector Object and calling getEntity method for fetch each bookmark object. But once I get first entity from layour collector, it makes other bookmarks as null.
Please find the code snippet . I am using Aspose 18.7 with Java 9.
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(document);
DocumentBuilder documentBuilder = new DocumentBuilder(document);
for (Table table : (Iterable<Table>) tables) {
Long time = System.currentTimeMillis();
logger.debug("[START] Prasing per table");
Map<Integer, Map<Integer, StringBuilder>> tableMatrix = new HashMap<Integer, Map<Integer, StringBuilder>>();
int rowIndex = 0;
int rowBookMarkIndex = 0;
Map<Integer, ParaData> bookMarkMap = new HashMap<>();
layoutCollector = new LayoutCollector(document);
for (Row row : table.getRows()) {
ParaData paraData = new ParaData();
documentBuilder.moveTo(row.getFirstCell().getFirstParagraph());
BookmarkStart start = documentBuilder.startBookmark("Bookmark start" + rowBookMarkIndex); //will be at the start of para of first cell
//documentBuilder.moveTo(row.getLastCell().getLastParagraph());
BookmarkEnd end = documentBuilder.endBookmark("Bookmark end" + rowBookMarkIndex); //will be at the end of para of last cell
paraData.setStart(start);
paraData.setEnd(end);
bookMarkMap.put(rowBookMarkIndex, paraData);
rowBookMarkIndex++;
}
layoutCollector = new LayoutCollector(document);
System.out.println("Layout Collector");
for (Map.Entry<Integer, ParaData> entry : bookMarkMap.entrySet()) {
//layoutCollector = new LayoutCollector(document);
Object bstart = layoutCollector.getEntity(entry.getValue().getStart());
Object bend = layoutCollector.getEntity(entry.getValue().getEnd());
if(bstart==null || bend==null){ // after first iteration, I am getting null here
System.out.println("null value");
}
entry.getValue().setBstart(bstart);
entry.getValue().setBend(bend);
}