pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1637734 - in /pdfbox/trunk/examples: ./ src/main/java/org/apache/pdfbox/examples/acroforms/ src/main/resources/org/apache/pdfbox/examples/ src/main/resources/org/apache/pdfbox/examples/acroforms/
Date Sun, 09 Nov 2014 21:00:00 GMT
Author: msahyoun
Date: Sun Nov  9 21:00:00 2014
New Revision: 1637734

URL: http://svn.apache.org/r1637734
Log:
PDFBOX-2340 add forms filling sample and resources

Added:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
  (with props)
    pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/
    pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/acroforms/
    pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/acroforms/FillFormField.pdf
  (with props)
Modified:
    pdfbox/trunk/examples/   (props changed)

Propchange: pdfbox/trunk/examples/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Nov  9 21:00:00 2014
@@ -2,3 +2,5 @@
 target
 .classpath
 .project
+
+.checkstyle

Added: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java?rev=1637734&view=auto
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
(added)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
Sun Nov  9 21:00:00 2014
@@ -0,0 +1,48 @@
+package org.apache.pdfbox.examples.acroforms;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+
+/**
+ * Example to show filling form fields.
+ * 
+ */
+public class FillFormField
+{
+
+    public static void main(String[] args) throws IOException
+    {
+        String formTemplate = "src/main/resources/org/apache/pdfbox/examples/acroforms/FillFormField.pdf";
+        String filledForm = "target/examples-output/FillFormField.pdf";
+        
+        // load the document
+        PDDocument pdfDocument = PDDocument
+                .loadNonSeq(new File(formTemplate),null);
+
+        // get the document catalog
+        PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
+        
+        // as there might not be an AcroForm entry a null check is necessary
+        if (acroForm != null)
+        {
+            // Retrieve an individual field and set it's value.
+            PDFieldTreeNode field = acroForm.getField( "sampleField" );
+            field.setValue("Text Entry");
+
+            // If a field is nested within the form tree a fully qualified name 
+            // might be provided to access the field.
+            field = acroForm.getField( "fieldsContainer.nestedSampleField" );
+            field.setValue("Text Entry");
+        }
+
+        // Save and close the filled out form.
+        pdfDocument.save(filledForm);
+        pdfDocument.close();
+    }
+
+}

Propchange: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/acroforms/FillFormField.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/acroforms/FillFormField.pdf
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/acroforms/FillFormField.pdf?rev=1637734&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/examples/acroforms/FillFormField.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/pdf



Mime
View raw message