pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1667904 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/cos/ main/java/org/apache/pdfbox/pdmodel/interactive/form/ test/java/org/apache/pdfbox/pdmodel/interactive/form/
Date Thu, 19 Mar 2015 23:59:51 GMT
Author: msahyoun
Date: Thu Mar 19 23:59:50 2015
New Revision: 1667904

URL: http://svn.apache.org/r1667904
Log:
PDFBOX-2718 allow to create new AcroForm fields from scratch

Added:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
  (with props)
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
  (with props)
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureFieldTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Thu Mar 19 23:59:50
2015
@@ -96,6 +96,8 @@ public final class COSName extends COSBa
     public static final COSName BOUNDS = new COSName("Bounds");
     public static final COSName BPC = new COSName("BPC");
     public static final COSName BS = new COSName("BS");
+    //** Acro form field type for button fields.
+    public static final COSName BTN = new COSName("Btn");
     public static final COSName BYTERANGE = new COSName("ByteRange");
     // C
     public static final COSName C = new COSName("C");
@@ -112,6 +114,8 @@ public final class COSName extends COSBa
     public static final COSName CENTER_WINDOW = new COSName("CenterWindow");
     public static final COSName CF = new COSName("CF");
     public static final COSName CFM = new COSName("CFM");
+    //** Acro form field type for choice fields.
+    public static final COSName CH = new COSName("Ch");
     public static final COSName CHAR_PROCS = new COSName("CharProcs");
     public static final COSName CHAR_SET = new COSName("CharSet");
     public static final COSName CICI_SIGNIT = new COSName("CICI.SignIt");
@@ -472,6 +476,8 @@ public final class COSName extends COSBa
     public static final COSName TRUE_TYPE = new COSName("TrueType");
     public static final COSName TRUSTED_MODE = new COSName("TrustedMode");
     public static final COSName TU = new COSName("TU");
+    /** Acro form field type for text field. */
+    public static final COSName TX = new COSName("Tx");
     public static final COSName TYPE = new COSName("Type");
     public static final COSName TYPE0 = new COSName("Type0");
     public static final COSName TYPE1 = new COSName("Type1");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
Thu Mar 19 23:59:50 2015
@@ -66,9 +66,10 @@ public abstract class PDButton extends P
      *
      * @param theAcroForm The acroform.
      */
-    PDButton(PDAcroForm theAcroForm)
+    public PDButton(PDAcroForm theAcroForm)
     {
         super( theAcroForm );
+        getDictionary().setItem(COSName.FT, COSName.BTN);
     }
     
     /**
@@ -78,11 +79,52 @@ public abstract class PDButton extends P
      * @param field the PDF object to represent as a field.
      * @param parentNode the parent node of the node to be created
      */
-    protected PDButton(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    public PDButton(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
     {
         super(acroForm, field, parentNode);
     }
     
+    /**
+     * Determines if push button bit is set.
+     * 
+     * @return true if type of button field is a push button.
+     */
+    public boolean isPushButton()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_PUSHBUTTON );
+    }
+
+    /**
+     * Set the push button bit.
+     *
+     * @param pushbutton if true the button field is treated as a push button field.
+     */
+    public void setPushButton( boolean pushbutton )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_PUSHBUTTON, pushbutton );
+    }
+
+    /**
+     * Determines if radio button bit is set.
+     * 
+     * @return true if type of button field is a push button.
+     */
+    public boolean isRadioButton()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_RADIO );
+    }
+
+    /**
+     * Set the radio button bit.
+     *
+     * @param radiobutton if true the button field is treated as a radio button field.
+     */
+    public void setRadioButton( boolean radiobutton )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_RADIO, radiobutton );
+    }   
+    
+    
     @Override
     public String getDefaultValue() throws IOException
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
Thu Mar 19 23:59:50 2015
@@ -50,9 +50,10 @@ public abstract class PDChoice extends P
      *
      * @param theAcroForm The acroform.
      */
-    protected PDChoice(PDAcroForm theAcroForm)
+    public PDChoice(PDAcroForm theAcroForm)
     {
         super( theAcroForm );
+        getDictionary().setItem(COSName.FT, COSName.CH);
     }
 
     /**
@@ -62,7 +63,7 @@ public abstract class PDChoice extends P
      * @param field the PDF object to represent as a field.
      * @param parentNode the parent node of the node to be created
      */
-    protected PDChoice(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    public PDChoice(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
     {
         super(acroForm, field, parentNode);
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
Thu Mar 19 23:59:50 2015
@@ -30,6 +30,17 @@ public final class PDComboBox extends PD
      *  Ff-flag.
      */
     private static final int FLAG_EDIT = 1 << 18;
+    
+    /**
+     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     *
+     * @param theAcroForm The acroform.
+     */
+    public PDComboBox(PDAcroForm theAcroForm)
+    {
+        super( theAcroForm );
+        setCombo(true);
+    }    
 
     /**
      * Constructor.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
Thu Mar 19 23:59:50 2015
@@ -32,11 +32,12 @@ public final class PDListBox extends PDC
      *
      * @param theAcroForm The acroform.
      */
-    protected PDListBox(PDAcroForm theAcroForm)
+    public PDListBox(PDAcroForm theAcroForm)
     {
         super( theAcroForm );
     }
     
+    
     /**
      * Constructor.
      * 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
Thu Mar 19 23:59:50 2015
@@ -29,7 +29,17 @@ import org.apache.pdfbox.cos.COSDictiona
  */
 public class PDPushButton extends PDButton
 {
-
+    /**
+     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     *
+     * @param theAcroForm The acroform.
+     */
+    public PDPushButton(PDAcroForm theAcroForm)
+    {
+        super( theAcroForm );
+        setPushButton(true);
+    }
+    
     /**
      * Constructor.
      * 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Thu Mar 19 23:59:50 2015
@@ -47,6 +47,7 @@ public final class PDRadioButton extends
     public PDRadioButton(PDAcroForm theAcroForm)
     {
         super( theAcroForm );
+        setRadioButton(true);
     }
     
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
Thu Mar 19 23:59:50 2015
@@ -54,6 +54,7 @@ public final class PDTextField extends P
     public PDTextField(PDAcroForm theAcroForm)
     {
         super( theAcroForm );
+        getDictionary().setItem(COSName.FT, COSName.TX);
     }
 
     /**

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java?rev=1667904&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
(added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
Thu Mar 19 23:59:50 2015
@@ -0,0 +1,61 @@
+package org.apache.pdfbox.pdmodel.interactive.form;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for the PDButton class.
+ *
+ */
+public class PDButtonTest
+{
+    private PDDocument document;
+    private PDAcroForm acroForm;
+
+    @Before
+    public void setUp()
+    {
+        document = new PDDocument();
+        acroForm = new PDAcroForm(document);
+    }
+
+    @Test
+    public void createCheckBox()
+    {
+        PDButton buttonField = new PDCheckbox(acroForm);
+        
+        assertEquals(buttonField.getFieldType(), buttonField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(buttonField.getFieldType(), "Btn");
+        assertFalse(buttonField.isPushButton());
+        assertFalse(buttonField.isRadioButton());
+    }
+
+    @Test
+    public void createPushButton()
+    {
+        PDButton buttonField = new PDPushButton(acroForm);
+        
+        assertEquals(buttonField.getFieldType(), buttonField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(buttonField.getFieldType(), "Btn");
+        assertTrue(buttonField.isPushButton());
+        assertFalse(buttonField.isRadioButton());
+    }
+
+    @Test
+    public void createRadioButton()
+    {
+        PDButton buttonField = new PDRadioButton(acroForm);
+        
+        assertEquals(buttonField.getFieldType(), buttonField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(buttonField.getFieldType(), "Btn");
+        assertTrue(buttonField.isRadioButton());
+        assertFalse(buttonField.isPushButton());
+    }
+}
+

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java?rev=1667904&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
(added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
Thu Mar 19 23:59:50 2015
@@ -0,0 +1,49 @@
+package org.apache.pdfbox.pdmodel.interactive.form;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for the PDChoice class.
+ *
+ */
+public class PDChoiceTest
+{
+    private PDDocument document;
+    private PDAcroForm acroForm;
+
+    @Before
+    public void setUp()
+    {
+        document = new PDDocument();
+        acroForm = new PDAcroForm(document);
+    }
+
+    @Test
+    public void createListBox()
+    {
+        PDChoice choiceField = new PDListBox(acroForm);
+        
+        assertEquals(choiceField.getFieldType(), choiceField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(choiceField.getFieldType(), "Ch");
+        assertFalse(choiceField.isCombo());
+    }
+
+    @Test
+    public void createComboBox()
+    {
+        PDChoice choiceField = new PDComboBox(acroForm);
+        
+        assertEquals(choiceField.getFieldType(), choiceField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(choiceField.getFieldType(), "Ch");
+        assertTrue(choiceField.isCombo());
+    }
+
+}
+

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureFieldTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureFieldTest.java?rev=1667904&r1=1667903&r2=1667904&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureFieldTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureFieldTest.java
Thu Mar 19 23:59:50 2015
@@ -28,7 +28,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Test for the PDAnnotation classes.
+ * Test for the PDSignatureField class.
  *
  */
 public class PDSignatureFieldTest
@@ -47,6 +47,10 @@ public class PDSignatureFieldTest
     public void createDefaultSignatureField() throws IOException
     {
         PDSignatureField sigField = new PDSignatureField(acroForm);
+        
+        assertEquals(sigField.getFieldType(), sigField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(sigField.getFieldType(), "Sig");
+        
         assertEquals(COSName.ANNOT, sigField.getDictionary().getItem(COSName.TYPE));
         assertEquals(PDAnnotationWidget.SUB_TYPE, sigField.getDictionary().getNameAsString(COSName.SUBTYPE));
     }

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java?rev=1667904&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
(added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
Thu Mar 19 23:59:50 2015
@@ -0,0 +1,53 @@
+package org.apache.pdfbox.pdmodel.interactive.form;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for the PDSignatureField class.
+ *
+ */
+public class PDTextFieldTest
+{
+    private PDDocument document;
+    private PDAcroForm acroForm;
+
+    @Before
+    public void setUp()
+    {
+        document = new PDDocument();
+        acroForm = new PDAcroForm(document);
+    }
+
+    @Test
+    public void createDefaultTextField()
+    {
+        PDFieldTreeNode textField = new PDTextField(acroForm);
+        
+        assertEquals(textField.getFieldType(), textField.getDictionary().getNameAsString(COSName.FT));
+        assertEquals(textField.getFieldType(), "Tx");
+    }
+
+    @Test
+    public void createWidgetForGet()
+    {
+        PDTextField textField = new PDTextField(acroForm);
+
+        assertNull(textField.getDictionary().getItem(COSName.TYPE));
+        assertNull(textField.getDictionary().getNameAsString(COSName.SUBTYPE));
+        
+        PDAnnotationWidget widget = textField.getWidget();
+        
+        assertEquals(COSName.ANNOT, textField.getDictionary().getItem(COSName.TYPE));
+        assertEquals(PDAnnotationWidget.SUB_TYPE, textField.getDictionary().getNameAsString(COSName.SUBTYPE));
+        
+        assertEquals(widget.getDictionary(), textField.getDictionary());
+    }
+
+}

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message