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

Bump org.apache.pdfbox.pdfbox from 2.0.27 to 3.0.0 #27

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.27', transitive: true
implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '3.0.0', transitive: true
implementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2', transitive: false
implementation group: 'org.assertj', name: 'assertj-core', version: '3.23.1', transitive: false
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/codeborne/pdftest/PDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.codeborne.pdftest.matchers.DoesNotContainExactText;
import com.codeborne.pdftest.matchers.DoesNotContainText;
import com.codeborne.pdftest.matchers.MatchesText;
import org.apache.pdfbox.io.RandomAccessRead;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
import org.apache.pdfbox.text.PDFTextStripper;
Expand All @@ -22,7 +25,6 @@

public class PDF {
public final byte[] content;

public final String text;
public final int numberOfPages;
public final String author;
Expand All @@ -44,8 +46,8 @@ private PDF(String name, byte[] content) {
private PDF(String name, byte[] content, int startPage, int endPage) {
this.content = content;

try (InputStream inputStream = new ByteArrayInputStream(content)) {
try (PDDocument pdf = PDDocument.load(inputStream)) {
try (RandomAccessRead buffer = new RandomAccessReadBuffer(content)) {
try (PDDocument pdf = new PDFParser(buffer).parse()) {
PDFTextStripper pdfTextStripper = new PDFTextStripper();
pdfTextStripper.setStartPage(startPage);
pdfTextStripper.setEndPage(endPage);
Expand Down Expand Up @@ -74,15 +76,15 @@ private PDF(String name, byte[] content, int startPage, int endPage) {
public PDF(File pdfFile) throws IOException {
this(pdfFile.getAbsolutePath(), readAllBytes(Paths.get(pdfFile.getAbsolutePath())));
}

public PDF(URL url) throws IOException {
this(url.toString(), readBytes(url));
}

public PDF(URI uri) throws IOException {
this(uri.toURL());
}

public PDF(byte[] content) {
this("", content);
}
Expand Down Expand Up @@ -151,5 +153,4 @@ public static Matcher<PDF> matchesText(String regex) {
public static Matcher<PDF> matchesText(Pattern regex) {
return new MatchesText(regex);
}

}
Loading