diff --git a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java index ff0f0365..73ac97c3 100644 --- a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java @@ -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; }