pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1743226 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java
Date Tue, 10 May 2016 16:30:40 GMT
Author: tilman
Date: Tue May 10 16:30:39 2016
New Revision: 1743226

URL: http://svn.apache.org/viewvc?rev=1743226&view=rev
Log:
PDFBOX-3346: example with empty signature

Added:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java
      - copied, changed from r1742454, pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java

Copied: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java
(from r1742454, pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java?p2=pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java&p1=pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java&r1=1742454&r2=1743226&rev=1743226&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmptySignatureForm.java
Tue May 10 16:30:39 2016
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.pdfbox.examples.interactive.form;
+package org.apache.pdfbox.examples.signature;
 
 import java.io.IOException;
 import org.apache.pdfbox.cos.COSName;
@@ -27,18 +27,17 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
 
 /**
- * An example of creating an AcroForm and a form field from scratch.
+ * An example of creating an AcroForm and an empty signature field from scratch.
  * 
- * The form field is created with properties similar to creating
- * a form with default settings in Adobe Acrobat.
+ * An actual signature can be added by clicking on it in Adobe Reader.
  * 
  */
-public final class CreateSimpleForm
+public final class CreateEmptySignatureForm
 {
-    private CreateSimpleForm()
+    private CreateEmptySignatureForm()
     {
     }
     
@@ -67,31 +66,18 @@ public final class CreateSimpleForm
         String defaultAppearanceString = "/Helv 0 Tf 0 g";
         acroForm.setDefaultAppearance(defaultAppearanceString);
         
-        // Add a form field to the form.
-        PDTextField textBox = new PDTextField(acroForm);
-        textBox.setPartialName("SampleField");
-        // Acrobat sets the font size to 12 as default
-        // This is done by setting the font size to '12' on the
-        // field level.
-        defaultAppearanceString = "/Helv 12 Tf 0 g";
-        textBox.setDefaultAppearance(defaultAppearanceString);
-        
-        // add the field to the acroform
-        acroForm.getFields().add(textBox);
-        
-        // Specify the annotation associated with the field
-        PDAnnotationWidget widget = textBox.getWidgets().get(0);
-        PDRectangle rect = new PDRectangle(50, 750, 200, 50);
+        // --- end of general AcroForm stuff ---
+        
+        // Create empty signature field, it will get the name "Signature1"
+        PDSignatureField signatureField = new PDSignatureField(acroForm);
+        PDAnnotationWidget widget = signatureField.getWidgets().get(0);
+        PDRectangle rect = new PDRectangle(50, 650, 200, 50);
         widget.setRectangle(rect);
         widget.setPage(page);
-        
-        // Add the annotation to the page
         page.getAnnotations().add(widget);
         
-        // set the field value
-        textBox.setValue("Sample field");
 
-        document.save("target/SimpleForm.pdf");
+        document.save("target/EmptySignatureForm.pdf");
         document.close();
     }
 }



Mime
View raw message