Skip to content

Commit

Permalink
fix: check if creating signature field is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Aug 20, 2024
1 parent aad94b7 commit bb7c5a1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/digital/slovensko/autogram/util/PDFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@

public class PDFUtils {
public static boolean isPdfAndPasswordProtected(DSSDocument document) {
if (document.getMimeType().equals(MimeTypeEnum.PDF)) {
try {
PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document);
if (!document.getMimeType().equals(MimeTypeEnum.PDF))
return false;

try {
PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document);

// document is protected against modification without password
if (!reader.canCreateSignatureField()) {
reader.close();
} catch (InvalidPasswordException e) {
return true;
} catch (IOException e) {
}
}

reader.close();
} catch (InvalidPasswordException e) {
return true;
} catch (IOException e) {}

return false;
}

Expand Down

0 comments on commit bb7c5a1

Please sign in to comment.