diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-03-24 13:02:08 +0100 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-03-24 13:02:08 +0100 |
commit | b448e46f6c6369b1dc6f7abcffc6606e50ef7848 (patch) | |
tree | 13e65e90314d821c974659530757e1af943e67b6 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow | |
parent | 26f7df3caceead74e209805de04057c9f72f3613 (diff) | |
download | pdf-over-b448e46f6c6369b1dc6f7abcffc6606e50ef7848.tar.gz pdf-over-b448e46f6c6369b1dc6f7abcffc6606e50ef7848.tar.bz2 pdf-over-b448e46f6c6369b1dc6f7abcffc6606e50ef7848.zip |
clean up encrypted pdf handling
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java | 12 |
1 files 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; } |