From f0e768ec1e098f0540df989dc280d9c8795dc70b Mon Sep 17 00:00:00 2001 From: pdanner Date: Mon, 24 Jan 2011 15:15:56 +0000 Subject: 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 --- .../wag/egov/egiz/pdf/StructContentHelper.java | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov') 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(); -- cgit v1.2.3