Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pagenumber in output json file #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/technology/tabula/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ public Table(ExtractionAlgorithm extractionAlgorithm) {

private int rowCount = 0;
private int colCount = 0;
private int pageNumber = 0;

/* visible for testing */ final TreeMap<CellPosition, RectangularTextContainer> cells = new TreeMap<>();

public int getRowCount() { return rowCount; }
public int getColCount() { return colCount; }
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int number) {
pageNumber = number;
}

public String getExtractionMethod() { return extractionMethod; }

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/technology/tabula/TableWithRulingLines.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public class TableWithRulingLines extends Table {
List<Ruling> verticalRulings, horizontalRulings;
RectangleSpatialIndex<Cell> si = new RectangleSpatialIndex<>();

public TableWithRulingLines(Rectangle area, List<Cell> cells, List<Ruling> horizontalRulings, List<Ruling> verticalRulings, ExtractionAlgorithm extractionAlgorithm) {
public TableWithRulingLines(Rectangle area, List<Cell> cells, List<Ruling> horizontalRulings, List<Ruling> verticalRulings, ExtractionAlgorithm extractionAlgorithm, int number) {
super(extractionAlgorithm);
this.setRect(area);
this.verticalRulings = verticalRulings;
this.horizontalRulings = horizontalRulings;
this.addCells(cells);
this.setPageNumber(number);
}

private void addCells(List<Cell> cells) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public int compare(Ruling arg0, Ruling arg1) {

Table table = new Table(this);
table.setRect(page.getLeft(), page.getTop(), page.getWidth(), page.getHeight());
table.setPageNumber(page.getPageNumber());

for (int i = 0; i < lines.size(); i++) {
Line line = lines.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ else if (r.vertical()) {
}
}

TableWithRulingLines t = new TableWithRulingLines(area, overlappingCells, horizontalOverlappingRulings, verticalOverlappingRulings, this);
TableWithRulingLines t = new TableWithRulingLines(area, overlappingCells, horizontalOverlappingRulings, verticalOverlappingRulings, this, page.getPageNumber());
spreadsheets.add(t);
}
Utils.sort(spreadsheets, Rectangle.ILL_DEFINED_ORDER);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/technology/tabula/json/TableSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public JsonElement serialize(Table table, Type type, JsonSerializationContext co
json.addProperty("height", table.getHeight());
json.addProperty("right", table.getRight());
json.addProperty("bottom", table.getBottom());
json.addProperty("page_number", table.getPageNumber());
json.add("data", data);

for (List<RectangularTextContainer> tableRow : table.getRows()) {
Expand Down