You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2014/11/09 22:00:22 UTC

pdfbox-docs git commit: PDFBOX-2340 AcroForms cookbook entry for trunk

Repository: pdfbox-docs
Updated Branches:
  refs/heads/master 0110155da -> d8848d0f5


PDFBOX-2340 AcroForms cookbook entry for trunk


Project: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/commit/d8848d0f
Tree: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/tree/d8848d0f
Diff: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/diff/d8848d0f

Branch: refs/heads/master
Commit: d8848d0f542b2253a753be9826d00bcb90536b2f
Parents: 0110155
Author: Maruan Sahyoun <sa...@fileaffairs.de>
Authored: Sun Nov 9 21:55:23 2014 +0100
Committer: Maruan Sahyoun <sa...@fileaffairs.de>
Committed: Sun Nov 9 21:55:23 2014 +0100

----------------------------------------------------------------------
 .../trunk/cookbook/acroforms/fill-form-field.md | 68 ++++++++++++++++++++
 1 file changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/pdfbox-docs/blob/d8848d0f/docs/trunk/cookbook/acroforms/fill-form-field.md
----------------------------------------------------------------------
diff --git a/docs/trunk/cookbook/acroforms/fill-form-field.md b/docs/trunk/cookbook/acroforms/fill-form-field.md
new file mode 100644
index 0000000..bdf3200
--- /dev/null
+++ b/docs/trunk/cookbook/acroforms/fill-form-field.md
@@ -0,0 +1,68 @@
+---
+license: Licensed to the Apache Software Foundation (ASF) under one
+         or more contributor license agreements.  See the NOTICE file
+         distributed with this work for additional information
+         regarding copyright ownership.  The ASF licenses this file
+         to you under the Apache License, Version 2.0 (the
+         "License"); you may not use this file except in compliance
+         with the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+         Unless required by applicable law or agreed to in writing,
+         software distributed under the License is distributed on an
+         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+         KIND, either express or implied.  See the License for the
+         specific language governing permissions and limitations
+         under the License.
+         
+title: Cookbook - Fill a Form Field
+---
+
+Fill a Form Field
+==================
+
+Form fields within a PDF are defined as part of the AcroForm entry within the PDF's document catalog.
+Form there individual fields can be accessed. Fields might be organized in a tree structure so it might
+be neccessary to walk through the tree to get an individual field.
+
+Load the PDF document.
+
+	:::java
+    // load the document
+    PDDocument pdfDocument = PDDocument.loadNonSeq(new File(... ), null);
+
+Get the docoument catalog and the AcroForm which might be contained within.
+
+	:::java
+    // get the document catalog
+	PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
+    PDAcroForm acroForm = docCatalog.getAcroForm();
+
+Retrieve an individual field and set it's value.
+
+	:::java
+    // as there might not be an AcroForm entry a null check is necessary
+    if (acroForm != null)
+    {
+        PDFieldTreeNode field = acroForm.getField( "fieldName" );
+        field.setValue("new field value");
+    }
+
+If a field is nested within the form tree a fully qualified name might be provided
+to access the field.
+
+	:::java
+    // as there might not be an AcroForm entry a null check is neccessary
+    if (acroForm != null)
+    {
+        PDFieldTreeNode field = acroForm.getField( "fieldsParentName.fieldName" );
+        field.setValue("new field value");
+    }
+    
+Save and close the filled out form.
+
+	:::java
+    doc.save(filledForm);
+    doc.close();
+