Skip to content

Commit

Permalink
Bump org.apache.pdfbox.pdfbox from 2.0.27 to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlogs authored and asolntsev committed Nov 6, 2023
1 parent da7aee4 commit 65260cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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);
}

}

0 comments on commit 65260cc

Please sign in to comment.