You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/08/22 15:18:19 UTC

svn commit: r1757202 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java

Author: tilman
Date: Mon Aug 22 15:18:19 2016
New Revision: 1757202

URL: http://svn.apache.org/viewvc?rev=1757202&view=rev
Log:
PDFBOX-3470: improve example with non standard text, border and background color

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateSimpleForm.java

Modified: 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/interactive/form/CreateSimpleForm.java?rev=1757202&r1=1757201&r2=1757202&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/interactive/form/CreateSimpleForm.java Mon Aug 22 15:18:19 2016
@@ -18,6 +18,7 @@
 package org.apache.pdfbox.examples.interactive.form;
 
 import java.io.IOException;
+import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
@@ -25,7 +26,10 @@ import org.apache.pdfbox.pdmodel.PDResou
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
 
@@ -72,8 +76,10 @@ public final class CreateSimpleForm
         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";
+        // field level. 
+        // The text color is set to blue in this example.
+        // To use black, replace "0 0 1 rg" with "0 0 0 rg" or "0 g".
+        defaultAppearanceString = "/Helv 12 Tf 0 0 1 rg";
         textBox.setDefaultAppearance(defaultAppearanceString);
         
         // add the field to the acroform
@@ -84,7 +90,15 @@ public final class CreateSimpleForm
         PDRectangle rect = new PDRectangle(50, 750, 200, 50);
         widget.setRectangle(rect);
         widget.setPage(page);
-        
+
+        // set green border and yellow background
+        // if you prefer defaults, just delete this code block
+        PDAppearanceCharacteristicsDictionary fieldAppearance
+                = new PDAppearanceCharacteristicsDictionary(new COSDictionary());
+        fieldAppearance.setBorderColour(new PDColor(new float[]{0,1,0}, PDDeviceRGB.INSTANCE));
+        fieldAppearance.setBackground(new PDColor(new float[]{1,1,0}, PDDeviceRGB.INSTANCE));
+        widget.setAppearanceCharacteristics(fieldAppearance);
+
         // make sure the annotation is visible on screen and paper
         widget.setPrinted(true);