From f891dca529c9dc199114ae4f0857d28812315b11 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 3 Apr 2014 15:38:01 +0200 Subject: Fixed Positioning to recognize Annotations --- .../lib/impl/signing/pdfbox/PADESPDFBOXSigner.java | 19 ++++++++++++ .../pdfbox/PDFAsVisualSignatureBuilder.java | 9 ++---- .../pdfbox/tagging/PDFBoxTaggingUtils.java | 35 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/tagging/PDFBoxTaggingUtils.java (limited to 'pdf-as-lib/src/main/java/at/gv') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index 767887b3..c04dca59 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -42,6 +42,8 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageNode; +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement; +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot; import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent; import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; @@ -69,6 +71,7 @@ import at.gv.egiz.pdfas.lib.impl.stamping.TableFactory; import at.gv.egiz.pdfas.lib.impl.stamping.ValueResolver; import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureProperties; import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PdfBoxVisualObject; +import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.tagging.PDFBoxTaggingUtils; import at.gv.egiz.pdfas.lib.impl.status.PDFObject; import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction; @@ -288,6 +291,22 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { e); } } + + /*if(signatureProfileSettings.isPDFA()) { + // Check for PDF-UA + PDDocumentCatalog root = doc.getDocumentCatalog(); + PDStructureTreeRoot treeRoot = root.getStructureTreeRoot(); + if(treeRoot != null) { + // Handle as PDF-UA + logger.info("Tree Root: {}", treeRoot.toString()); + PDStructureElement docElement = PDFBoxTaggingUtils.getDocumentElement(treeRoot); + PDStructureElement sigBlock = new PDStructureElement("Table", docElement); + root.getCOSObject().setNeedToBeUpdate(true); + docElement.getCOSObject().setNeedToBeUpdate(true); + treeRoot.getCOSObject().setNeedToBeUpdate(true); + sigBlock.setTitle("Signature Table"); + } + }*/ options.setPreferedSignatureSize(0x1000); options.setPage(positioningInstruction.getPage()); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java index 0b183c08..e24ff939 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java @@ -41,14 +41,13 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.settings.ISettings; -import at.gv.egiz.pdfas.lib.test.mains.TestPDFBoxTable; import at.knowcenter.wag.egov.egiz.table.Entry; import at.knowcenter.wag.egov.egiz.table.Style; public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { private static final Logger logger = LoggerFactory - .getLogger(TestPDFBoxTable.class); + .getLogger(PDFAsVisualSignatureBuilder.class); private void drawTable(PDPage page, PDPageContentStream contentStream, float x, float y, PDFBoxTable abstractTable, PDDocument doc, @@ -157,9 +156,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { String text = (String) cell.getValue(); float ttexty = texty - padding - fontSize; - // COSName name = COSName.getPDFName("ANDI_TAG!"); - // contentStream.beginMarkedContentSequence(COSName.ALT, - // name); + //COSName name = COSName.getPDFName("ANDI_TAG!"); + //contentStream.beginMarkedContentSequence(COSName.ALT, name); String fontName = textFont.equals(PDType1Font.COURIER) ? "COURIER" : "HELVETICA"; contentStream.beginText(); @@ -254,7 +252,6 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { private PDFAsVisualSignatureProperties properties; private ISettings settings; -// private List addedFonts = new ArrayList(); private PDResources innerFormResources; private Map images = new HashMap(); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/tagging/PDFBoxTaggingUtils.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/tagging/PDFBoxTaggingUtils.java new file mode 100644 index 00000000..3501e354 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/tagging/PDFBoxTaggingUtils.java @@ -0,0 +1,35 @@ +package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.tagging; + +import java.util.Iterator; +import java.util.List; + +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDMarkedContentReference; +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement; +import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureNode; +import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent; + +public class PDFBoxTaggingUtils { + + public static String DOCUMENT = "Document"; + + public static void beginMarkedContent(PDMarkedContentReference reference) { + PDMarkedContentReference ref; + PDMarkedContent mc; + } + + public static PDStructureElement getDocumentElement(PDStructureNode structElem) { + List kids = structElem.getKids(); + Iterator kidsit = kids.iterator(); + while (kidsit.hasNext()) { + Object kid = kidsit.next(); + if (kid instanceof PDStructureElement) { + PDStructureElement elem = (PDStructureElement) kid; + if(elem.getStructureType().equals(DOCUMENT)) { + return elem; + } + } + } + return null; + } + +} -- cgit v1.2.3