aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2011-01-24 15:15:56 +0000
committerpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2011-01-24 15:15:56 +0000
commitf0e768ec1e098f0540df989dc280d9c8795dc70b (patch)
treeda49b995a03c574a11cdfe021b407d418c13d2e4
parent6bea54a7ed2ff7edb0ab4f49e7a035a2aa7284ae (diff)
downloadpdf-as-3-f0e768ec1e098f0540df989dc280d9c8795dc70b.tar.gz
pdf-as-3-f0e768ec1e098f0540df989dc280d9c8795dc70b.tar.bz2
pdf-as-3-f0e768ec1e098f0540df989dc280d9c8795dc70b.zip
added manual calculation of parentTreeNextKey because some pdfcreators don't build this key as they should
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@725 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
-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();