aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-15 10:11:39 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-15 10:11:39 +0200
commit8b6eeda673ab545dadf6ffedde1654f6a0604428 (patch)
treef29fe23d753259bd83e48af32f9852720064c401
parent68e996fe190e6ba9e7aa46cf81bae8e762f53256 (diff)
downloadpdf-as-4-8b6eeda673ab545dadf6ffedde1654f6a0604428.tar.gz
pdf-as-4-8b6eeda673ab545dadf6ffedde1654f6a0604428.tar.bz2
pdf-as-4-8b6eeda673ab545dadf6ffedde1654f6a0604428.zip
TTF Fonts width fix, null value in signature block fix, Signature reason from config
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java1
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java10
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java6
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java34
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java5
5 files changed, 51 insertions, 5 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java
index 02780b8c..aaa00ed6 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java
@@ -89,5 +89,6 @@ public interface IProfileConstants {
public final static String TMP_DIR_DEFAULT_VALUE = "pdfastmp";
public final static String SIGNING_REASON = "adobeSignReasonValue";
+ public final static String SIGNFIELD_VALUE = "adobeSignFieldValue";
public final static String SIG_PDFA1B_VALID = "SIG_PDFA1B_VALID";
}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
index 84a9e6f8..45b5c375 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
@@ -133,7 +133,7 @@ public class SignatureProfileSettings implements IProfileConstants {
String value = others.get(key);
key = key.substring(key.lastIndexOf('.') + 1);
- profileSettings.put(key, others.get(value));
+ profileSettings.put(key, value);
logger.debug(" Settings: " + key + " : " + value);
}
@@ -180,6 +180,10 @@ public class SignatureProfileSettings implements IProfileConstants {
return value;
}
+ String v = profileSettings.get(key);
+ if (v != null) {
+ return v;
+ }
return getDefaultValue(key);
}
@@ -191,6 +195,10 @@ public class SignatureProfileSettings implements IProfileConstants {
return this.getValue(SIGNING_REASON);
}
+ public String getSignFieldValue() {
+ return this.getValue(SIGNFIELD_VALUE);
+ }
+
public boolean isPDFA() {
SignatureProfileEntry entry = profileInformations.get(SIG_PDFA1B_VALID);
if (entry != null) {
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java
index d0a9fee7..c110b93d 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java
@@ -62,6 +62,12 @@ public class StringUtils {
public static String convertStringToPDFFormat(String value)
throws UnsupportedEncodingException {
+
+ if(value == null) {
+ logger.warn("Trying to convert null string!");
+ return value;
+ }
+
byte[] replace_bytes = applyWinAnsiEncoding(value);
String restored_value = unapplyWinAnsiEncoding(replace_bytes);
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 44919b1c..8694017f 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
@@ -128,7 +128,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
if (signerReason == null) {
signerReason = "PAdES Signature";
}
-
+
signature.setReason(signerReason);
logger.debug("Signing reason: " + signerReason);
@@ -139,7 +139,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
signer.setPDSignature(signature);
SignatureOptions options = new SignatureOptions();
-
+
// Is visible Signature
if (requestedSignature.isVisual()) {
logger.info("Creating visual siganture block");
@@ -321,6 +321,36 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
doc.addSignature(signature, signer, options);
+ String sigFieldName = signatureProfileSettings.getSignFieldValue();
+
+ if(sigFieldName != null) {
+ PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
+ if (acroForm != null) {
+ @SuppressWarnings("unchecked")
+ List<PDField> fields = acroForm.getFields();
+ PDSignatureField signatureField = null;
+
+ if (fields != null) {
+ for (PDField pdField : fields) {
+ if (pdField instanceof PDSignatureField) {
+ if (((PDSignatureField) pdField).getSignature().getDictionary()
+ .equals(signature.getDictionary())) {
+ signatureField = (PDSignatureField) pdField;
+ }
+ }
+ }
+ } else {
+ logger.warn("Failed to name Signature Field! [Cannot find Field list in acroForm!]");
+ }
+
+ if(signatureField != null) {
+ signatureField.setPartialName(sigFieldName);
+ }
+ } else {
+ logger.warn("Failed to name Signature Field! [Cannot find acroForm!]");
+ }
+ }
+
if (requestedSignature.isVisual()) {
// if(requestedSignature.getSignaturePosition().)
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
index 1d8928aa..c6d515f9 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
@@ -374,9 +374,10 @@ public class PDFBoxTable {
float fwidth;
if (c instanceof PDType1Font) {
fwidth = c.getFontDescriptor().getFontBoundingBox().getWidth()
- / 1000 * fontSize;
+ / 1000.0f * fontSize;
} else {
- fwidth = c.getFontDescriptor().getMaxWidth();
+ fwidth = c.getStringWidth("abcdefghijklmnopqrstuvwxyz ") / 1000.0f * fontSize;
+ fwidth = fwidth / (float)"abcdefghijklmnopqrstuvwxyz".length();
}
logger.debug("Font Width: {}", fwidth);