pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1753579 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible: PDFTemplateCreator.java PDFTemplateStructure.java
Date Wed, 20 Jul 2016 17:23:52 GMT
Author: tilman
Date: Wed Jul 20 17:23:52 2016
New Revision: 1753579

URL: http://svn.apache.org/viewvc?rev=1753579&view=rev
Log:
PDFBOX-3017: deprecate / remove poorly named method "getTemplateAppearanceStream"

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java?rev=1753579&r1=1753578&r2=1753579&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java
Wed Jul 20 17:23:52 2016
@@ -18,12 +18,15 @@ package org.apache.pdfbox.pdmodel.intera
 
 import java.awt.geom.AffineTransform;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdfwriter.COSWriter;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
@@ -152,7 +155,7 @@ public class PDFTemplateCreator
         pdfBuilder.createVisualSignature(template);
         pdfBuilder.createWidgetDictionary(pdSignatureField, holderFormResources);
         
-        ByteArrayInputStream in = pdfStructure.getTemplateAppearanceStream();
+        InputStream in = getVisualSignatureAsStream(pdfStructure.getVisualSignature());
         logger.info("stream returning started, size= " + in.available());
         
         // we must close the document
@@ -161,4 +164,13 @@ public class PDFTemplateCreator
         // return result of the stream 
         return in;
     }
+
+    private InputStream getVisualSignatureAsStream(COSDocument visualSignature) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        COSWriter writer = new COSWriter(baos);
+        writer.write(visualSignature);
+        writer.close();
+        return new ByteArrayInputStream(baos.toByteArray());
+    }
 }

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java?rev=1753579&r1=1753578&r2=1753579&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java
Wed Jul 20 17:23:52 2016
@@ -61,7 +61,7 @@ public class PDFTemplateStructure
     private PDResources holderFormResources;
     private PDFormXObject holderForm;
     private PDAppearanceDictionary appearanceDictionary;
-    private PDStream innterFormStream;
+    private PDStream innerFormStream;
     private PDResources innerFormResources;
     private PDFormXObject innerForm;
     private PDStream imageFormStream;
@@ -362,7 +362,7 @@ public class PDFTemplateStructure
      */
     public PDStream getInnerFormStream()
     {
-        return innterFormStream;
+        return innerFormStream;
     }
 
     /**
@@ -371,7 +371,7 @@ public class PDFTemplateStructure
      */
     public void setInnterFormStream(PDStream innerFormStream)
     {
-        this.innterFormStream = innerFormStream;
+        this.innerFormStream = innerFormStream;
     }
 
     /**
@@ -567,12 +567,27 @@ public class PDFTemplateStructure
     {
         this.acroFormFields = acroFormFields;
     }
-    
-   /**
-    * Gets AP of the created template
-    * @return the templates Appearance Stream
-    * @throws IOException
-    */
+
+    /**
+     * Returns the visual signature COSDocument as a stream and closes the template field
+     * PDDocument.
+     *
+     * @return the visual signature COSDocument as a stream
+     * @throws IOException
+     * @deprecated This will be removed in 2.1 because the method name is misleading and
confusing,
+     * and the work done rather belongs into the calling class:
+     * <pre>
+     * {@code
+     * COSDocument visualSignature = structure.getVisualSignature();
+     *  ByteArrayOutputStream baos = new ByteArrayOutputStream();
+     *  COSWriter writer = new COSWriter(baos);
+     *  writer.write(visualSignature);
+     *  writer.close();
+     *  structure.getTemplate().close();
+     *  ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+     * } </pre>
+     */
+    @Deprecated
     public ByteArrayInputStream getTemplateAppearanceStream() throws IOException
     {
         COSDocument visualSignature = getVisualSignature();



Mime
View raw message