diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java | 4 | ||||
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/AdobeSignatureHelper.java | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java b/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java index 4fec0a1..122aec8 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java +++ b/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java @@ -3,6 +3,8 @@ */
package at.gv.egiz.pdfas.api.commons;
+import at.knowcenter.wag.egov.egiz.pdf.AdobeSignatureHelper;
+
/**
* Contains commonly used constants.
*
@@ -112,6 +114,8 @@ public final class Constants public static final String TEMP_DIR_NAME = "pdfastmp";
public static final String BKU_HEADER_SIGNATURE_LAYOUT = "SignatureLayout";
+
+ public static final String ADOBE_SIG_FILTER = AdobeSignatureHelper.ADOBE_SIG_FILTER;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AdobeSignatureHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AdobeSignatureHelper.java index 6a7c545..9a52a84 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AdobeSignatureHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AdobeSignatureHelper.java @@ -1,12 +1,14 @@ package at.knowcenter.wag.egov.egiz.pdf;
import java.util.HashMap;
+import java.util.Iterator;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.log4j.Logger;
+import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
import at.gv.egiz.pdfas.utils.OgnlUtil;
@@ -16,9 +18,11 @@ import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PdfDate;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfName;
+import com.lowagie.text.pdf.PdfObject;
import com.lowagie.text.pdf.PdfSignature;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import com.lowagie.text.pdf.PdfStamper;
@@ -31,7 +35,7 @@ import com.lowagie.text.pdf.PdfString; *
*/
public class AdobeSignatureHelper {
- private static final String ADOBE_SIGN_FIELDNAME_KEY = "adobeSignFieldName";
+ private static final String ADOBE_SIGN_FIELDNAME_KEY = "adobeSignFieldValue";
private static final String ADOBE_SIG_ENABLED_KEY = "adobeSignEnabled";
@@ -54,17 +58,36 @@ public class AdobeSignatureHelper { SignatureObject so, ActualTablePos atp) throws PresentableException {
try {
- logger.info("create adobe signature field");
+ logger.debug("Creating adobe signature field.");
PdfSignatureAppearance sap = stamper.getSignatureAppearance();
String fieldName = getAdobeFieldName(so.getSignatureTypeDefinition().getType());
// find field num
+ /*
int nexSigNum = 1;
String finalFieldName = fieldName + " #" + nexSigNum;
+
while (stamper.getAcroFields().getField(finalFieldName) != null) {
nexSigNum++;
finalFieldName = fieldName + " #" + nexSigNum;
}
+ */
+
+ AcroFields af = stamper.getAcroFields();
+ Iterator signatureNamesIt = af.getSignatureNames().iterator();
+ PdfName referenceFilterName = new PdfName(ADOBE_SIG_FILTER);
+ int nextSigNum = 1;
+ while (signatureNamesIt.hasNext()) {
+ PdfDictionary dictionary = (PdfDictionary) af.getSignatureDictionary((String) signatureNamesIt.next());
+ PdfObject filterName = dictionary.get(PdfName.FILTER);
+ if (filterName != null && filterName.isName()) {
+ PdfName name = (PdfName) filterName;
+ if (referenceFilterName.equals(name)) {
+ nextSigNum++;
+ }
+ }
+ }
+ String finalFieldName = fieldName + " #" + nextSigNum;
sap.setCrypto(null, null, null, null);
// supress overlay text for visible signatures
@@ -88,11 +111,15 @@ public class AdobeSignatureHelper { // sig.setReason("reason is not visible");
// sig.setContact("contact is not visible");
// sig.setDate(new PdfDate());
+
+ /* disabled in order to align adobe signature appearance for textual signatures with binary signatures
if (si != null) {
XMLGregorianCalendar c = DatatypeFactory.newInstance().newXMLGregorianCalendar(
si.getSignSignatureObject().date);
sig.setDate(new PdfDate(c.toGregorianCalendar()));
}
+ */
+
sig.setName(getAdobeSignText(so.getSignatureTypeDefinition().getType(), si));
sap.setCryptoDictionary(sig);
|