Skip to content

Instantly share code, notes, and snippets.

@atirtahirgroupdocs
Last active July 24, 2017 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atirtahirgroupdocs/f7328001ea72b796d42b50a4e893ebe9 to your computer and use it in GitHub Desktop.
Save atirtahirgroupdocs/f7328001ea72b796d42b50a4e893ebe9 to your computer and use it in GitHub Desktop.
AnnotationConfig cfg = Utilities.getConfiguration();
AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
DocumentInfoContainer documentInfoContainer = annotator.getDocumentInfo(fileName);
// Go through all pages
for (PageData pageData : documentInfoContainer.getPages()) {
System.out.println("Page number: " + pageData.getNumber());
// Go through all page rows
for (int i = 0; i < pageData.getRows().size(); i++) {
RowData rowData = pageData.getRows().get(i);
// Write data to console
System.out.println("Row: " + (i + 1));
System.out.println("Text: " + rowData.getText());
System.out.println("Text width: " + rowData.getLineWidth());
System.out.println("Text height: " + rowData.getLineHeight());
System.out.println("Distance from left: " + rowData.getLineLeft());
System.out.println("Distance from top: " + rowData.getLineTop());
// Get words
String[] words = rowData.getText().split(" ");
// Go through all word coordinates
for (int j = 0; j < words.length; j++) {
int coordinateIndex = j == 0 ? 0 : j + 1;
// Write data to console
System.out.println("Word: '" + words[j] + "'");
System.out.println("Word distance from left: " + rowData.getTextCoordinates().get(coordinateIndex));
System.out.println("Word width: " + rowData.getTextCoordinates().get(coordinateIndex + 1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment