aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/pdfas
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java2
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java15
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java35
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java1
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java12
5 files changed, 47 insertions, 18 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
index bb747bc6..d6ed2028 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
@@ -104,10 +104,12 @@ public class PdfAsFactory {
configuration.getAbsolutePath());
PropertyConfigurator.configure(new FileInputStream(
log4j));
+ logger.info("Configured Log4j with: " + log4j.getAbsolutePath());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
+
log_configured = true;
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
index 25e57188..cf7376c2 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
@@ -135,7 +135,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
logger.trace("sign started");
verifySignParameter(parameter);
-
+ OperationStatus status = null;
try {
// Status initialization
if (!(parameter.getConfiguration() instanceof ISettings)) {
@@ -143,7 +143,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
}
ISettings settings = (ISettings) parameter.getConfiguration();
- OperationStatus status = new OperationStatus(settings, parameter);
+ status = new OperationStatus(settings, parameter);
// set Original PDF Document Data
status.getPdfObject().setOriginalDocument(
@@ -199,6 +199,11 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
e);
throw new PdfAsException("error.pdf.sig.01", e);
} finally {
+ if(status != null) {
+ if(status.getPdfObject() != null) {
+ status.getPdfObject().close();
+ }
+ }
logger.trace("sign done");
}
}
@@ -437,6 +442,12 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
return createSignResult(status);
} catch (IOException e) {
throw new PdfAsException("error.pdf.sig.06", e);
+ } finally {
+ if(status != null) {
+ if(status.getPdfObject() != null) {
+ status.getPdfObject().close();
+ }
+ }
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
index 1175e2dc..854559d2 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
@@ -23,8 +23,6 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl.signing.pdfbox;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -42,8 +40,6 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageNode;
-import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
-import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot;
import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
@@ -71,7 +67,6 @@ import at.gv.egiz.pdfas.lib.impl.stamping.TableFactory;
import at.gv.egiz.pdfas.lib.impl.stamping.ValueResolver;
import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureProperties;
import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PdfBoxVisualObject;
-import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.tagging.PDFBoxTaggingUtils;
import at.gv.egiz.pdfas.lib.impl.status.PDFObject;
import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature;
import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
@@ -222,10 +217,10 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
properties.buildSignature();
- ByteArrayOutputStream sigbos = new ByteArrayOutputStream();
+ /*ByteArrayOutputStream sigbos = new ByteArrayOutputStream();
sigbos.write(StreamUtils.inputStreamToByteArray(properties
.getVisibleSignature()));
- sigbos.close();
+ sigbos.close();*/
if (signaturePlaceholderData != null) {
// Placeholder found!
@@ -305,8 +300,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
options.setPreferedSignatureSize(0x1000);
options.setPage(positioningInstruction.getPage());
- options.setVisualSignature(new ByteArrayInputStream(sigbos
- .toByteArray()));
+ options.setVisualSignature(properties
+ .getVisibleSignature());
}
doc.addSignature(signature, signer, options);
@@ -314,18 +309,23 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// pdfbox patched (FIS -> IS)
doc.saveIncremental(fis, fos);
fis.close();
+ fos.flush();
fos.close();
-
+ fos = null;
+
fis = new FileInputStream(new File(fisTmpFile));
// write to resulting output stream
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- bos.write(StreamUtils.inputStreamToByteArray(fis));
- fis.close();
- bos.close();
-
- pdfObject.setSignedDocument(bos.toByteArray());
+ //ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ //bos.write();
+ //bos.close();
+
+ pdfObject.setSignedDocument(StreamUtils.inputStreamToByteArray(fis));
+ fis.close();
+ fis = null;
+ System.gc();
+
helper.deleteFile(fisTmpFile);
} catch (IOException e) {
@@ -337,6 +337,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
} catch (COSVisitorException e) {
logger.error(MessageResolver.resolveMessage("error.pdf.sig.01"), e);
throw new PdfAsException("error.pdf.sig.01", e);
+ } finally {
+ logger.info("Signature done!");
+
}
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
index e7582137..528e4d6a 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
@@ -126,6 +126,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
//in = pdfStructure.getTemplateAppearanceStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
template.save(baos);
+ baos.close();
in = new ByteArrayInputStream(baos.toByteArray());
}
catch (COSVisitorException e)
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
index f8ca3567..6aff5495 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
@@ -48,6 +48,18 @@ public class PDFObject {
}
}
+ public void close() {
+ if(doc != null) {
+ try {
+ doc.close();
+ //System.gc();
+ } catch(Throwable e) {
+ // ignore!
+ }
+ doc = null;
+ }
+ }
+
public byte[] getOriginalDocument() {
return originalDocument;
}