From b448e46f6c6369b1dc6f7abcffc6606e50ef7848 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 24 Mar 2022 13:02:08 +0100 Subject: clean up encrypted pdf handling --- .../asit/pdfover/gui/workflow/states/PositioningState.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 83a9ac79..9a881687 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -42,6 +42,7 @@ import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.SignaturePosition; import com.sun.pdfview.PDFFile; +import com.sun.pdfview.decrypt.UnsupportedEncryptionException; import com.sun.pdfview.decrypt.PDFAuthenticationFailureException; /** * Decides where to position the signature block @@ -80,15 +81,20 @@ public class PositioningState extends State { try { pdf = new PDFFile(buf); + if (pdf.getNumPages() > 0) + pdf.getPage(1); + else + throw new IOException(); } catch (PDFAuthenticationFailureException e) { throw new IOException(Messages.getString("error.PDFPwdProtected"), e); } catch (IOException e) { - throw new IOException(Messages.getString("error.MayNotBeAPDF"), e); //$NON-NLS-1$ + if (e.getCause() instanceof UnsupportedEncryptionException) + throw new IOException(Messages.getString("error.PDFProtected")); + else + throw new IOException(Messages.getString("error.MayNotBeAPDF"), e); } - if (pdf.getDefaultDecrypter().isEncryptionPresent()) - throw new IOException(Messages.getString("error.PDFProtected")); //$NON-NLS-1$ return pdf; } -- cgit v1.2.3