pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1845605 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java
Date Fri, 02 Nov 2018 16:34:04 GMT
Author: tilman
Date: Fri Nov  2 16:34:04 2018
New Revision: 1845605

URL: http://svn.apache.org/viewvc?rev=1845605&view=rev
Log:
PDFBOX-4366: add test

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java?rev=1845605&r1=1845604&r2=1845605&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java
Fri Nov  2 16:34:04 2018
@@ -25,8 +25,16 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+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.annotation.PDBorderStyleDictionary;
 
 /**
  * This will test the functionality of Radio Buttons in PDFBox.
@@ -107,4 +115,40 @@ public class TestCheckBox extends TestCa
             assertEquals(checkBox.getExportValues(), new ArrayList<String>());
         }
     }
+
+    /**
+     * PDFBOX-4366: Create and test a checkbox with no /AP. The created file works with Adobe
Reader!
+     * 
+     * @throws IOException 
+     */
+    public void testCheckBoxNoAppearance() throws IOException
+    {
+        try (PDDocument doc = new PDDocument())
+        {
+            PDPage page = new PDPage();
+            doc.addPage(page);
+            PDAcroForm acroForm = new PDAcroForm(doc);
+            acroForm.setNeedAppearances(true); // need this or it won't appear on Adobe Reader
+            doc.getDocumentCatalog().setAcroForm(acroForm);
+            List<PDField> fields = new ArrayList<>();
+            PDCheckBox checkBox = new PDCheckBox(acroForm);
+            checkBox.setPartialName("checkbox");
+            PDAnnotationWidget widget = checkBox.getWidgets().get(0);
+            widget.setRectangle(new PDRectangle(50, 600, 100, 100));
+            PDBorderStyleDictionary bs = new PDBorderStyleDictionary();
+            bs.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
+            bs.setWidth(1);
+            COSDictionary acd = new COSDictionary();
+            PDAppearanceCharacteristicsDictionary ac = new PDAppearanceCharacteristicsDictionary(acd);
+            ac.setBackground(new PDColor(new float[] { 1, 1, 0 }, PDDeviceRGB.INSTANCE));
+            ac.setBorderColour(new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE));
+            ac.setNormalCaption("4"); // 4 is checkmark, 8 is cross
+            widget.setAppearanceCharacteristics(ac);
+            widget.setBorderStyle(bs);
+            checkBox.setValue("Off");
+            fields.add(checkBox);
+            page.getAnnotations().add(widget);
+            acroForm.setFields(fields);
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message