summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-07-15 15:30:11 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-07-15 15:30:11 +0200
commit3011a7561a30005efc929e9ad4c681a7653e8ba7 (patch)
tree309bbbda6c89a0e9f0353372d86a3725a23a641e /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java
parent145dc4e64898572353de3e92bb3d365ccdf8f02f (diff)
downloadpdf-over-3011a7561a30005efc929e9ad4c681a7653e8ba7.tar.gz
pdf-over-3011a7561a30005efc929e9ad4c681a7653e8ba7.tar.bz2
pdf-over-3011a7561a30005efc929e9ad4c681a7653e8ba7.zip
kill pdfview, cf. #104
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java31
1 files changed, 11 insertions, 20 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 b09728c9..aff0fe61 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
@@ -22,6 +22,8 @@ import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.eclipse.swt.SWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,9 +43,6 @@ import at.asit.pdfover.signator.Emblem;
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
*/
@@ -68,14 +67,14 @@ public class PositioningState extends State {
private File loadedDocumentPath = null;
- private PDFFile document = null;
+ private PDDocument document = null;
private void closePDFDocument() {
if (this.document != null)
{
+ try { this.document.close(); } catch (IOException e) { log.warn("Failed to close PDF", e); }
this.document = null;
- System.gc(); /* try to get Java to close the mapped file... */
}
this.loadedDocumentPath = null;
}
@@ -83,34 +82,26 @@ public class PositioningState extends State {
private void openPDFDocument() throws IOException {
closePDFDocument();
File documentPath = getStateMachine().status.document;
- PDFFile pdf = null;
- RandomAccessFile rafile = new RandomAccessFile(documentPath, "r");
- FileChannel chan = rafile.getChannel();
- ByteBuffer buf = chan.map(FileChannel.MapMode.READ_ONLY, 0, chan.size());
- chan.close();
- rafile.close();
+ PDDocument pdf = null;
try
{
- pdf = new PDFFile(buf);
- if (pdf.getNumPages() > 0)
- pdf.getPage(1);
+ pdf = PDDocument.load(documentPath);
+ if (pdf.getNumberOfPages() > 0)
+ pdf.getPage(0);
else
throw new IOException();
}
- catch (PDFAuthenticationFailureException e) {
+ catch (InvalidPasswordException e) {
throw new IOException(Messages.getString("error.PDFPwdProtected"), e);
}
catch (IOException e) {
- if (e.getCause() instanceof UnsupportedEncryptionException)
- throw new IOException(Messages.getString("error.PDFProtected"));
- else
- throw new IOException(Messages.getString("error.MayNotBeAPDF"), e);
+ throw new IOException(Messages.getString("error.MayNotBeAPDF"), e);
}
this.document = pdf;
this.loadedDocumentPath = documentPath;
}
- private PositioningComposite getPositioningComposite(PDFFile document) {
+ private PositioningComposite getPositioningComposite(PDDocument document) {
StateMachine stateMachine = getStateMachine();
if (this.positionComposite == null) {
this.positionComposite =