diff options
author | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-11-03 11:07:58 +0000 |
---|---|---|
committer | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-11-03 11:07:58 +0000 |
commit | dc8b7fd3ecfdcefbaa8625c94ed48a22ce095940 (patch) | |
tree | c420696271337f6c453fa80b0f968245be8d46b3 /src/main/java/at/knowcenter/wag | |
parent | 95c11be9df0a8b1de53bf39c4d9d2c23ff330fff (diff) | |
download | pdf-as-3-dc8b7fd3ecfdcefbaa8625c94ed48a22ce095940.tar.gz pdf-as-3-dc8b7fd3ecfdcefbaa8625c94ed48a22ce095940.tar.bz2 pdf-as-3-dc8b7fd3ecfdcefbaa8625c94ed48a22ce095940.zip |
added alt text
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@599 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java index 07f2328..19a32ac 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java @@ -3,7 +3,10 @@ package at.knowcenter.wag.egov.egiz.pdf; import org.apache.log4j.Logger;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import com.lowagie.text.pdf.PdfArray;
import com.lowagie.text.pdf.PdfContentByte;
@@ -15,17 +18,21 @@ import com.lowagie.text.pdf.PdfNumber; import com.lowagie.text.pdf.PdfObject;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfStamperImp;
+import com.lowagie.text.pdf.PdfString;
/**
* Helper class for writing the structure hierarchy of the signature elements.
* Everything is written with the PdfObject low level API because there is no better support.
* The structured content is only written for structured (==tagged) input documents. The methods have to be called in the
- * defined order. The object cannot be reused for several signatures.
+ * defined order. The object cannot be reused for several signatures.<br>
+ * See pdf spec "Logical Structure" for details.
* @author exthex
*
*/
public class StructContentHelper {
private static Logger logger = Logger.getLogger(StructContentHelper.class);
+
+ private final static String ALT_TEXT_KEY = "sigBlockAltText";
private int nextMcid = 0;
private boolean isTagged = false;
@@ -49,8 +56,7 @@ public class StructContentHelper { * Create and write structured content for signature block
* @throws PresentableException
*/
- void buildMainStructData() throws PresentableException {
- // TODO titel/alttext woher?
+ void buildMainStructData(SignatureObject so, SignatorInformation si) throws PresentableException {
try {
@@ -137,7 +143,7 @@ public class StructContentHelper { newStruct.put(PdfName.TYPE, new PdfName("StructElem"));
newStruct.put(PdfName.PG, page.getIndRef());
- //newStruct.put(PdfName.ALT, new PdfString("meine feiner signaturblock alttext"));
+ newStruct.put(PdfName.ALT, new PdfString(createAltText(so, si)));
newStruct.put(PdfName.K, new PdfNumber(nextMcid));
@@ -273,5 +279,32 @@ public class StructContentHelper { private PdfDictionary getStructTreeRoot() {
return stamper.getReader().getCatalog().getAsDict(PdfName.STRUCTTREEROOT);
}
+
+ private String createAltText(SignatureObject so, SignatorInformation si) {
+ String profileId = so.getSignatureTypeDefinition().getType();
+ String res = getAltText(profileId); // ask config for alt text
+ if (res == null) {
+ // make default alt text
+ StringBuilder sb = new StringBuilder("PDF-AS Signatur");
+
+ try {
+ if (so != null && so.getKZ() != null) {
+ sb.append(". ").append(so.getKZ().toString());
+ } else if (si != null) {
+ sb.append(". ").append(si.getSignSignatureObject().kz);
+ }
+ } catch (InvalidIDException e) {
+ logger.debug("error reading signature method for alt text string");
+ }
+ sb.append(". ").append(profileId);
+ res = sb.toString();
+ }
+ return res;
+ }
+
+ public static String getAltText(String sigProfile) {
+ return AdobeSignatureHelper.getDefaultableConfigProperty(sigProfile, ALT_TEXT_KEY, null);
+ }
+
}
|