diff options
4 files changed, 79 insertions, 77 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 6cdfa0b3..2c2b941b 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 @@ -92,4 +92,6 @@ public interface IProfileConstants { public final static String SIGNFIELD_VALUE = "adobeSignFieldValue"; public final static String TIMEZONE_BASE = "timezone"; public final static String SIG_PDFA1B_VALID = "SIG_PDFA1B_VALID"; + public final static String SIG_PDFUA_FORCE = "SIG_PDFUA_FORCE"; + } 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 dc1250fb..cbc1d601 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 @@ -212,4 +212,13 @@ public class SignatureProfileSettings implements IProfileConstants { } return false; } + + public boolean isPDFUA() { + SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE); + if (entry != null) { + String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } } diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index ce341023..2e133284 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -53,6 +53,7 @@ import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageNode; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode; +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDAttributeObject; import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement; import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot; import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent; @@ -110,7 +111,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { RequestedSignature requestedSignature, PDFASSignatureInterface genericSigner) throws PdfAsException { String fisTmpFile = null; - + PDFAsVisualSignatureProperties properties=null; if (!(genericPdfObject instanceof PDFBOXObject)) { @@ -475,100 +476,88 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { logger.warn("Failed to name Signature Field! [Cannot find acroForm!]"); } - //marked sig - if (signatureProfileSettings.isPDFA()) { // Check for - // PDF-UA - PDDocumentCatalog root = doc.getDocumentCatalog(); - PDStructureTreeRoot treeRoot = - root.getStructureTreeRoot(); - if (treeRoot != null) { // Handle as PDF-UA + // PDF-UA + if (signatureProfileSettings.isPDFUA()==true) { + try{ + PDDocumentCatalog root = doc.getDocumentCatalog(); + PDStructureTreeRoot treeRoot = root.getStructureTreeRoot(); - logger.info("Tree Root: {}", treeRoot.toString()); - PDStructureTreeRoot rootElement = doc.getDocumentCatalog().getStructureTreeRoot(); - List<Object> kids = rootElement.getKids(); + if (treeRoot != null) { //check if structure tree available in pdf document + logger.info("Tree Root: {}", treeRoot.toString()); + List<Object> kids = treeRoot.getKids(); - PDStructureElement docElement = null; + if(kids==null){ + logger.info("No kid-elements in structure tree Root, maybe not PDF/UA document"); + } - for(Object k: kids){ - if(k instanceof PDStructureElement){ - if(((PDStructureElement) k).getStructureType().equals("Document")){ + PDStructureElement docElement = null; + for(Object k: kids){ + if(k instanceof PDStructureElement){ docElement=(PDStructureElement) k; + break; + // if(((PDStructureElement) k).getStructureType().equals("Document")){ + // docElement=(PDStructureElement) k; + // } } } - } - - PDStructureElement sigBlock = new PDStructureElement( - "Form", docElement); - - COSDictionary objectdic= new COSDictionary(); - objectdic.setName("Type", "OBJR"); - objectdic.setItem("Pg", signatureField.getWidget().getPage()); - objectdic.setItem("Obj", signatureField.getWidget()); - - //page cannot be set here-->leads to pdfua syntax error - // PDObjectReference pr = new PDObjectReference(); - // pr.setReferencedObject(signatureField.getWidget()); - - - sigBlock.setTitle("Signature Table"); + PDStructureElement sigBlock = new PDStructureElement( + "Form", docElement); - // COSDictionary dict = new COSDictionary();//(COSDictionary) atto.getCOSObject(); - // dict.setName("O", "Layout"); - // dict.setName("Placement", "Block"); - // PDAttributeObject atto =PDAttributeObject.create(dict); - // - // sigBlock.addAttribute(atto); - // atto.getCOSObject().setNeedToBeUpdate(true); + //create object dictionary and add as child element + COSDictionary objectdic= new COSDictionary(); + objectdic.setName("Type", "OBJR"); + objectdic.setItem("Pg", signatureField.getWidget().getPage()); + objectdic.setItem("Obj", signatureField.getWidget()); + List<Object> l = new ArrayList<Object>(); + l.add(objectdic); + sigBlock.setKids(l); + sigBlock.setTitle("Signature Table"); + sigBlock.setParent(docElement); + docElement.appendKid(sigBlock); + //Create and add Attribute dictionary to mitigate PAC warning + COSDictionary sigBlockDic = (COSDictionary) sigBlock.getCOSObject(); + COSDictionary sub = new COSDictionary(); - //PDMarkedContent pdm = new PDMarkedContent("test", properties) + sub.setName("O", "Layout"); + sub.setName("Placement", "Block"); + sigBlockDic.setItem(COSName.A, sub); + sigBlockDic.setNeedToBeUpdate(true); - List<Object> l = new ArrayList<Object>(); - l.add(objectdic); - sigBlock.setKids(l); + //Modify number tree + PDNumberTreeNode ntn = treeRoot.getParentTree(); + if(ntn==null){ + ntn = new PDNumberTreeNode(objectdic, null); + logger.info("No number-tree-node found!"); + } - sigBlock.setParent(docElement); - //sigBlock.setPage(signatureField.getWidget().getPage()); - docElement.appendKid(sigBlock); - - PDNumberTreeNode ntn = treeRoot.getParentTree(); - if(ntn==null) - ntn = new PDNumberTreeNode(objectdic, null); - - //int index=ntn.getUpperLimit(); - - COSDictionary ntndic=ntn.getCOSDictionary(); - COSArray ntndicnumbersarray = (COSArray)ntndic.getDictionaryObject(COSName.NUMS); - int lastindex = ntndicnumbersarray.size(); - - ntndicnumbersarray.add(lastindex, new COSInteger(lastindex-1)); - ntndicnumbersarray.add(lastindex+1, sigBlock.getCOSObject()); - - treeRoot.setParentTree(ntn); - - treeRoot.setParentTreeNextKey(lastindex); - + COSDictionary ntndic=ntn.getCOSDictionary(); + COSArray ntndicnumbersarray = (COSArray)ntndic.getDictionaryObject(COSName.NUMS); + int arrindex = ntndicnumbersarray.size(); + int treeindex = arrindex/2; - PDAnnotationWidget widg=signatureField.getWidget(); - widg.setStructParent(lastindex-1); - ntndicnumbersarray.setNeedToBeUpdate(true); + ntndicnumbersarray.add(arrindex, COSInteger.get(treeindex)); + ntndicnumbersarray.add(arrindex+1, sigBlock.getCOSObject()); - ntndic.setNeedToBeUpdate(true); - docElement.getCOSObject().setNeedToBeUpdate(true); - sigBlock.getCOSObject().setNeedToBeUpdate(true); - docElement.getCOSObject().setNeedToBeUpdate(true); - rootElement.getCOSObject().setNeedToBeUpdate(true); - signatureField.getWidget().getPage().findResources().getCOSObject() - .setNeedToBeUpdate(true); + treeRoot.setParentTree(ntn); + treeRoot.setParentTreeNextKey(treeindex+1); + //setStructureParent + PDAnnotationWidget widg=signatureField.getWidget(); + widg.setStructParent(treeindex); - treeRoot.getCOSObject().setNeedToBeUpdate(true); - root.getCOSObject().setNeedToBeUpdate(true); - objectdic.getCOSObject().setNeedToBeUpdate(true); + ntndic.setNeedToBeUpdate(true); + sigBlock.getCOSObject().setNeedToBeUpdate(true); + treeRoot.getCOSObject().setNeedToBeUpdate(true); + objectdic.getCOSObject().setNeedToBeUpdate(true); + } + }catch(Exception e){ + logger.error("Could not create PDF-UA conform document!"); + logger.debug(e.getMessage()); } } diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java index 6074b4c9..9b0f5ae1 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java @@ -52,7 +52,7 @@ public class TableDrawUtils { public static final String TABLE_DEBUG = "debug.table"; - private static StringBuilder alternateTableCaption = new StringBuilder(); + private static StringBuilder alternateTableCaption; public static void drawTable(PDPage page, PDPageContentStream contentStream, float x, float y, float width, @@ -61,6 +61,8 @@ public class TableDrawUtils { Map<String, ImageObject> images, ISettings settings, IDGenerator generator, PDFAsVisualSignatureProperties properties) throws PdfAsException { + alternateTableCaption = new StringBuilder(); + logger.debug("Drawing Table: X {} Y {} WIDTH {} HEIGHT {} \n{}", x, y, width, height, abstractTable.getOrigTable().toString()); |