pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1869951 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Date Sun, 17 Nov 2019 20:53:22 GMT
Author: tilman
Date: Sun Nov 17 20:53:22 2019
New Revision: 1869951

URL: http://svn.apache.org/viewvc?rev=1869951&view=rev
Log:
PDFBOX-4689: create COSDocument with annotation and appearance for invisible signature that
is to be treated like a visible signature

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1869951&r1=1869950&r2=1869951&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Nov 17
20:53:22 2019
@@ -21,6 +21,7 @@ import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -66,6 +67,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.ExternalSigningSupport;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface;
@@ -430,8 +432,7 @@ public class PDDocument implements Close
         // Distinction of case for visual and non-visual signature
         if (visualSignature == null)
         {
-            prepareNonVisibleSignature(signatureField);
-            return;
+            visualSignature = createInvisibleSignatureCOSDocument();
         }
 
         prepareVisibleSignature(signatureField, acroForm, visualSignature);
@@ -530,6 +531,30 @@ public class PDDocument implements Close
         return false;
     }
 
+    private COSDocument createInvisibleSignatureCOSDocument() throws IOException
+    {
+        // This document must be tailored so that prepareVisibleSignature() finds all it
wants.
+        PDDocument doc = new PDDocument();
+        PDPage page = new PDPage();
+        List<PDAnnotation> annots = new ArrayList<>();
+        PDAnnotationWidget widget = new PDAnnotationWidget();
+        widget.getCOSObject().setItem(COSName.FT, COSName.SIG);
+        widget.setRectangle(new PDRectangle());
+        PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
+        PDAppearanceStream appearanceStream = new PDAppearanceStream(doc);
+        appearanceStream.setBBox(new PDRectangle());
+        appearanceDictionary.setNormalAppearance(appearanceStream);
+        widget.setAppearance(appearanceDictionary);
+        annots.add(widget);
+        page.setAnnotations(annots);
+        doc.addPage(page);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        doc.save(baos);
+        doc.close();
+        // need to save and reload so that COSDocument has an object list
+        return PDDocument.load(baos.toByteArray()).getDocument();
+    }
+
     private void prepareVisibleSignature(PDSignatureField signatureField, PDAcroForm acroForm,

             COSDocument visualSignature)
     {



Mime
View raw message