Skip to content

Commit

Permalink
Upgrade apache pdfbox to version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
eivinhb committed Jan 5, 2024
1 parent 2a875a2 commit b9cda43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
14 changes: 11 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
Digipost Printability Validator

Copyright 2023 Posten Norge AS. All Rights Reserved.
Copyright 2024 Posten Norge AS. All Rights Reserved.

This product includes software developed by Posten Norge AS. - https://www.posten.no/
Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html


This software includes third party software subject to the following licenses:

Apache FontBox under Apache License, Version 2.0
Apache PDFBox under Apache License, Version 2.0
Apache FontBox under Apache-2.0
Apache PDFBox under Apache-2.0
Apache PDFBox io under Apache-2.0
Digipost Printability Validator under The Apache Software License, Version 2.0
JCL 1.2 implemented over SLF4J under Apache License, Version 2.0
JUnit Jupiter (Aggregator) under Eclipse Public License v2.0
JUnit Jupiter Engine under Eclipse Public License v2.0
JUnit Jupiter Params under Eclipse Public License v2.0
JUnit Platform Commons under Eclipse Public License v2.0
JUnit Platform Engine API under Eclipse Public License v2.0
org.apiguardian:apiguardian-api under The Apache License, Version 2.0
org.opentest4j:opentest4j under The Apache License, Version 2.0
SLF4J API Module under MIT License


18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<slf4j-api.version>2.0.9</slf4j-api.version>
<slf4j-api.version>2.0.10</slf4j-api.version>
</properties>

<dependencies>
Expand All @@ -57,7 +57,18 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.27</version>
<version>3.0.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-io</artifactId>
<version>3.0.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand Down Expand Up @@ -219,7 +230,8 @@
<include>org.slf4j</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.hamcrest</include>
<include>org.junit.jupiter:junit-jupiter-api</include>
<include>org.junit.jupiter:*</include>
<include>org.junit.platform:*</include>
<include>org.opentest4j:opentest4j</include>
<include>org.apiguardian:apiguardian-api</include>
<include>org.junit.platform:junit-platform-commons</include>
Expand Down
2 changes: 1 addition & 1 deletion src/NOTICE.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Digipost Printability Validator

Copyright 2023 Posten Norge AS. All Rights Reserved.
Copyright 2024 Posten Norge AS. All Rights Reserved.

This product includes software developed by Posten Norge AS. - https://www.posten.no/
Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/no/digipost/print/validate/PdfValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package no.digipost.print.validate;

import no.digipost.print.validate.PdfValidationSettings.Bleed;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.io.RandomAccessInputStream;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
Expand Down Expand Up @@ -85,7 +88,7 @@ public PdfValidationResult validate(Path pdfFile, PdfValidationSettings printVal
private PdfValidationResult validateForPrint(InputStream pdfStream, PdfValidationSettings printValidationSettings) {
int numberOfPages = -1;
List<PdfValidationError> errors;
try (PDDocument pdDoc = PDDocument.load(pdfStream)) {
try (PDDocument pdDoc = Loader.loadPDF(new RandomAccessReadBuffer(pdfStream))) {
numberOfPages = pdDoc.getNumberOfPages();
errors = validateDocumentForPrint(pdDoc, printValidationSettings);
} catch (InvalidPasswordException invalidPassword) {
Expand Down Expand Up @@ -195,7 +198,7 @@ private void validerSideantall(int numberOfPages, int maxPages, final List<PdfVa
}
if (numberOfPages == 0) {
errors.add(PdfValidationError.DOCUMENT_HAS_NO_PAGES);
LOG.debug("The PDF document does not contain any pages. The file may be corrupt.", numberOfPages);
LOG.debug("The PDF document does not contain any pages. The file may be corrupt.");
}
}

Expand Down Expand Up @@ -243,7 +246,7 @@ private boolean hasTextInArea(PDPage pdPage, Rectangle2D area) throws IOExceptio
stripper.addRegion("marginArea", area);
stripper.extractRegions(pdPage);
String text = stripper.getTextForRegion("marginArea");
if (text != null && text.trim().length() > 0) {
if (text != null && !text.trim().isEmpty()) {
hasTextInArea = true;
}
return hasTextInArea;
Expand Down

0 comments on commit b9cda43

Please sign in to comment.