aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/StructContentHelper.java27
1 files changed, 22 insertions, 5 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 55e77e0..b15b3d6 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
@@ -16,7 +16,6 @@ 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.
@@ -28,6 +27,8 @@ import com.lowagie.text.pdf.PdfString;
*
*/
public class StructContentHelper {
+ private static final PdfName PARENTTREENEXTKEY = new PdfName("ParentTreeNextKey");
+
private static final String ALT_TEXT_DEFAULT = "PDF-AS Signatur";
private static Logger logger = Logger.getLogger(StructContentHelper.class);
@@ -85,7 +86,14 @@ public class StructContentHelper {
}
if (strucParNr == null) { // no StructParents entry yet, make new one
- parentTreeNextKey = root.getAsNumber(new PdfName("ParentTreeNextKey")); // read next proposed key
+ parentTreeNextKey = root.getAsNumber(PARENTTREENEXTKEY); // read next proposed key
+ if (parentTreeNextKey == null) { // this can be null if a non-perfect pdf creator was at work
+ // find the next key by counting
+ int nextI = ((int) parentTreeNums.size() / 2);
+ this.parentTreeNextKey = new PdfNumber(nextI);
+ root.put(PARENTTREENEXTKEY, this.parentTreeNextKey);
+ }
+
parentTreeKey = new PdfNumber(parentTreeNextKey.intValue());
parentTreeNextKey.increment();
page.put(PdfName.STRUCTPARENTS, parentTreeKey); // write /StructParents entry to page
@@ -101,9 +109,18 @@ public class StructContentHelper {
} else {
parentTreeKey = strucParNr;
+ parentTreeNextKey = root.getAsNumber(PARENTTREENEXTKEY); // read next proposed key
+ if (parentTreeNextKey == null) { // this can be null if a non-perfact pdf creator was at work
+ // find the next key by counting
+ int nextI = 0;
+ if (parentTreeNums != null) {
+ nextI = ((int) parentTreeNums.size() / 2);
+ }
+ this.parentTreeNextKey = new PdfNumber(nextI);
+ root.put(PARENTTREENEXTKEY, this.parentTreeNextKey);
+ }
}
-
// find my structParentEntry
if (numsIdx < 0) {
// it's a weird data structure: "number tree", see pdf reference if you really want to understand
@@ -143,7 +160,7 @@ public class StructContentHelper {
newStruct.put(PdfName.TYPE, new PdfName("StructElem"));
newStruct.put(PdfName.PG, page.getIndRef());
- newStruct.put(PdfName.ALT, new PdfString(getAltText(so.getSignatureTypeDefinition().getType())));
+ // newStruct.put(PdfName.ALT, new PdfString(getAltText(so.getSignatureTypeDefinition().getType())));
newStruct.put(PdfName.K, new PdfNumber(nextMcid));
@@ -201,7 +218,7 @@ public class StructContentHelper {
if (this.isTagged) {
// new parent tree entry
if (parentTreeNextKey == null) {
- parentTreeNextKey = getStructTreeRoot().getAsNumber(new PdfName("ParentTreeNextKey")); // read next proposed key
+ parentTreeNextKey = getStructTreeRoot().getAsNumber(PARENTTREENEXTKEY); // read next proposed key
}
annotationParentTreeKey = new PdfNumber(parentTreeNextKey.intValue());
parentTreeNextKey.increment();