forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilsForTesting.java
More file actions
47 lines (37 loc) · 1.55 KB
/
UtilsForTesting.java
File metadata and controls
47 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package technology.tabula;
import java.io.IOException;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import static org.junit.Assert.*;
public class UtilsForTesting {
public static Page getAreaFromFirstPage(String path, float top, float left, float bottom, float right) throws IOException {
return getAreaFromPage(path, 1, top, left, bottom, right);
}
public static Page getAreaFromPage(String path, int page, float top, float left, float bottom, float right) throws IOException {
return getPage(path, page).getArea(top, left, bottom, right);
}
public static Page getPage(String path, int pageNumber) throws IOException {
ObjectExtractor oe = null;
try {
PDDocument document = PDDocument
.load(path);
oe = new ObjectExtractor(document);
Page page = oe.extract(pageNumber);
return page;
} finally {
if (oe != null)
oe.close();
}
}
public static void assertTableEquals(Table table, String[][] arrayOfRows) {
List<List<RectangularTextContainer>> tableRows = table.getRows();
assertEquals(arrayOfRows.length, tableRows.size());
for (int i = 0; i < arrayOfRows.length; i++) {
String[] row = arrayOfRows[i];
assertEquals(row.length, tableRows.get(i).size());
for (int j = 0; j < row.length; j++) {
assertEquals(row[j].trim(), table.getCell(i, j).getText().trim());
}
}
}
}