This repository was archived by the owner on Jan 7, 2024. It is now read-only.
forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectExtractor.java
More file actions
67 lines (45 loc) · 1.95 KB
/
ObjectExtractor.java
File metadata and controls
67 lines (45 loc) · 1.95 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package technology.tabula;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class ObjectExtractor {
private final PDDocument pdfDocument;
public ObjectExtractor(PDDocument pdfDocument) {
this.pdfDocument = pdfDocument;
}
protected Page extractPage(Integer pageNumber) throws IOException {
if (pageNumber > this.pdfDocument.getNumberOfPages() || pageNumber < 1) {
throw new java.lang.IndexOutOfBoundsException(
"Page number does not exist");
}
PDPage p = this.pdfDocument.getPage(pageNumber - 1);
ObjectExtractorStreamEngine se = new ObjectExtractorStreamEngine(p);
se.processPage(p);
TextStripper pdfTextStripper = new TextStripper(this.pdfDocument, pageNumber);
pdfTextStripper.process();
Utils.sort(pdfTextStripper.textElements, Rectangle.ILL_DEFINED_ORDER);
float w, h;
int pageRotation = p.getRotation();
if (Math.abs(pageRotation) == 90 || Math.abs(pageRotation) == 270) {
w = p.getCropBox().getHeight();
h = p.getCropBox().getWidth();
} else {
w = p.getCropBox().getWidth();
h = p.getCropBox().getHeight();
}
return new Page(0, 0, w, h, pageRotation, pageNumber, p, this.pdfDocument, pdfTextStripper.textElements,
se.rulings, pdfTextStripper.minCharWidth, pdfTextStripper.minCharHeight, pdfTextStripper.spatialIndex);
}
public PageIterator extract(Iterable<Integer> pages) {
return new PageIterator(this, pages);
}
public PageIterator extract() {
return extract(Utils.range(1, this.pdfDocument.getNumberOfPages() + 1));
}
public Page extract(int pageNumber) {
return extract(Utils.range(pageNumber, pageNumber + 1)).next();
}
public void close() throws IOException {
this.pdfDocument.close();
}
}