Skip to content
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<!-- Main dependency versions (centralized) -->
<lombok.version>1.18.38</lombok.version>
<pdfbox.version>2.0.32</pdfbox.version>
<pdfbox.version>3.0.8</pdfbox.version>
<json.version>20250107</json.version>
<commons-io.version>2.22.0</commons-io.version>
<flying-saucer.version>9.1.22</flying-saucer.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
Expand All @@ -26,8 +27,8 @@
* @return the names of the files that were written (empty if the PDF has no attachments)
* @throws IOException if the PDF cannot be read or an attachment cannot be written
*/
public static List<String> extractAttachments(String src, String dir) throws IOException {

Check warning on line 30 in src/main/java/com/rsh/jtoolkit/pdf/ExtractAttachments.java

View workflow job for this annotation

GitHub Actions / build (21)

[MixedMutabilityReturnType] This method returns both mutable and immutable collections or maps from different paths. This may be confusing for users of the method.
try (PDDocument document = PDDocument.load(new File(src))) {
try (PDDocument document = Loader.loadPDF(new File(src))) {
PDDocumentNameDictionary names = new PDDocumentNameDictionary(document.getDocumentCatalog());
PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles();
if (embeddedFiles == null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/rsh/jtoolkit/pdf/PdfUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDMetadata;

Expand All @@ -17,14 +18,14 @@ private PdfUtil() {}
* metadata.
*/
public static boolean isPdfA(String filePath) throws IOException {
try (PDDocument document = PDDocument.load(new File(filePath))) {
try (PDDocument document = Loader.loadPDF(new File(filePath))) {
return isPdfA(document);
}
}

/** Returns {@code true} if the PDF read from {@code inputStream} declares PDF/A conformance. */
public static boolean isPdfA(InputStream inputStream) throws IOException {
try (PDDocument document = PDDocument.load(inputStream)) {
try (PDDocument document = Loader.loadPDF(inputStream.readAllBytes())) {
return isPdfA(document);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/rsh/jtoolkit/pdf/sign/PDFSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Enumeration;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
Expand All @@ -26,6 +27,7 @@
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
Expand All @@ -50,13 +52,13 @@

public class PDFSigner implements SignatureInterface {

private static final PDFont FONT = PDType1Font.HELVETICA_BOLD;
private static final PDFont FONT = new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD);
private static final float FONT_SIZE = 10;
private static final float LEADING = FONT_SIZE * 1.5f;
private PrivateKey privateKey;
private Certificate[] certificateChain;

public PDFSigner(KeyStore keystore, char[] pin)

Check warning on line 61 in src/main/java/com/rsh/jtoolkit/pdf/sign/PDFSigner.java

View workflow job for this annotation

GitHub Actions / build (21)

[NullAway] initializer method does not guarantee @nonnull fields privateKey (line 58), certificateChain (line 59) are initialized along all control-flow paths (remember to check for exceptions or early returns).
throws KeyStoreException,
UnrecoverableKeyException,
NoSuchAlgorithmException,
Expand Down Expand Up @@ -112,7 +114,7 @@

public void signPDF(InputStream inputFile, ByteArrayOutputStream fos, PDRectangle rect)
throws IOException {
try (PDDocument doc = PDDocument.load(inputFile)) {
try (PDDocument doc = Loader.loadPDF(inputFile.readAllBytes())) {
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
Expand Down Expand Up @@ -50,7 +51,7 @@ void signsPdfAndAddsSignatureDictionary() throws Exception {

byte[] signed = out.toByteArray();
assertTrue(signed.length > source.length, "signed PDF should be larger than the source");
try (PDDocument doc = PDDocument.load(signed)) {
try (PDDocument doc = Loader.loadPDF(signed)) {
assertFalse(doc.getSignatureDictionaries().isEmpty(), "expected a signature dictionary");
}
}
Expand Down
Loading