Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class FormEditor

java.lang.Object
  extended bycom.aspose.pdf.kit.FormEditor

public class FormEditor
extends java.lang.Object

Represents a class which is used to edit AcroForms Field in existing pdf documents. Users can add/delete all kinds of fields, and set their attributes and appearance as well.

     //open the document and create a FormEditor object
     FormEditor formEditor = new FormEditor(path + "fieldAdd.pdf", path + "added.pdf");
     //create a FormFieldFacade to specify visual attributes
     FormFieldFacade facade = new FormFieldFacade();
     formEditor.setFacade(facade);

      //add a button field with grey background and beveled border
      facade.setBackgroudColor(new java.awt.Color(0xCC, 0xCC, 0xCC));
      facade.setBorderStyle(FormFieldFacade.BDSTYLE_BEVELED);
      formEditor.addField(FormEditor.FLDTYP_BTNFLD, "button1", "OK", 1, new Rectangle(265, 695, 100, 25));

      //add a text field with blue dashed border, green background, and red inverse text
      facade.setBorderColor(new java.awt.Color(0, 0, 255));
      facade.setBorderStyle(FormFieldFacade.BDSTYLE_DASHED);
      facade.setBorderWidth(FormFieldFacade.BDWIDTH_THICK);
      facade.setBackgroudColor(new java.awt.Color(0, 255, 0));
      facade.setAlignment(FormFieldFacade.ALIGN_CENTER);
      facade.setFont(FontStyle.TimesBoldItalic);
      facade.setTextColor(new java.awt.Color(255, 0, 0));
      facade.setFontSize(12);
      facade.setRotation(180);
      formEditor.addField(FormEditor.FLDTYP_TXTFLD, "text1", "This is a line", 1, new Rectangle(215, 647, 200, 25));
      //clear the settings
      formEditor.resetFacade();

       //Close the document
      formEditor.close();
 


Field Summary
static int FLDTYP_BTNFLD
          Defines a button field type.
static int FLDTYP_CHKBOX
          Defines a check box field type.
static int FLDTYP_COMBOBOX
          Defines a combo box field type.
static int FLDTYP_LIST
          Defines a list field type.
static int FLDTYP_OTHERS
          Defines unknown field type.
static int FLDTYP_RADIOBTN
          Defines a radio button field type.
static int FLDTYP_TXTFLD
          Defines a single text field type.
 
Constructor Summary
FormEditor(java.io.InputStream srcStream, java.io.OutputStream dstStream)
          Represents a constructor of the FormEditor object with source stream and destination stream.
FormEditor(java.io.InputStream srcStream, java.lang.String desFilename)
          Represents a constructor of the FormEditor object with source stream and destination file.
FormEditor(java.lang.String srcFilename, java.io.OutputStream dstStream)
          Represents a constructor of the FormEditor object with source file and destination stream.
FormEditor(java.lang.String srcFilename, java.lang.String desFilename)
          Represents a constructor of the FormEditor object with source file and destination file.
 
Method Summary
 void addField(int fieldType, java.lang.String fieldName, java.lang.String value, int pageNum, java.awt.Rectangle rect)
          Insert a specified field into existing PDF document at corresponding position.
 void close()
          Saves all the modifications and closes the destination file.
 void decorateField()
          Change visual attributes of all fields.
 void decorateField(int fieldType)
          Change visual attributes of all fields with the same field type.
 void decorateField(java.lang.String fieldName)
          Change visual attributes of the specified field.
 void localCopyField(java.lang.String fieldName, java.lang.String newFieldName, int pageNum)
          Copy an existing field from current page to another page in the same position.
 void localCopyField(java.lang.String fieldName, java.lang.String newFieldName, int pageNum, float abscissa, float ordinate)
          Copies an existing field to a new position pecified by page number and ordinates.
 void moveTo(java.lang.String fieldName, float right, float up)
          Moves the field to a new position specifying by relative offsets.
 void moveTo(java.lang.String fieldName, float llx, float lly, float urx, float ury)
          Moves the field to a new position specifying by a couple of vertexs.
 void removeField(java.lang.String fieldName)
          Remove a field specified by fieldName.
 void renameField(java.lang.String fieldName, java.lang.String newFieldName)
          Change a field's name.
 void resetFacade()
          Reset all visual attributes to default values.
 void setFacade(FormFieldFacade facade)
          Setter of member facade.
 void setFieldAttr(java.lang.String fieldName, int flag)
           
 void setFieldFlag(java.lang.String fieldName, int flag)
          Sets the field's appearance flags, including displayed, printed, zoomed, or rotated.
 void setItems(java.lang.String[] mItems)
          Set items for combo box/list/radio box fields creation.
 void setRadioGap(float radioGap)
          Setter of radioGap.
 void setRadioHoriz(boolean radioHoriz)
          Setter of radioHoriz.
 void setSubmitBtnUrl(java.lang.String fieldName, java.lang.String url)
          Sets the url destination of a filed, only effective to submit buttons.
 void zoom(java.lang.String fieldName, float scale)
          Zooms the field proportionately according to the specific scale.
 void zoom(java.lang.String fieldName, float scaleLength, float scaleWidth)
          Zooms the field according to the specific scales.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLDTYP_BTNFLD

public static final int FLDTYP_BTNFLD
Defines a button field type.

See Also:
Constant Field Values

FLDTYP_CHKBOX

public static final int FLDTYP_CHKBOX
Defines a check box field type.

See Also:
Constant Field Values

FLDTYP_RADIOBTN

public static final int FLDTYP_RADIOBTN
Defines a radio button field type.

See Also:
Constant Field Values

FLDTYP_TXTFLD

public static final int FLDTYP_TXTFLD
Defines a single text field type.

See Also:
Constant Field Values

FLDTYP_LIST

public static final int FLDTYP_LIST
Defines a list field type.

See Also:
Constant Field Values

FLDTYP_COMBOBOX

public static final int FLDTYP_COMBOBOX
Defines a combo box field type.

See Also:
Constant Field Values

FLDTYP_OTHERS

public static final int FLDTYP_OTHERS
Defines unknown field type.

See Also:
Constant Field Values
Constructor Detail

FormEditor

public FormEditor(java.lang.String srcFilename,
                  java.lang.String desFilename)
           throws java.lang.Exception
Represents a constructor of the FormEditor object with source file and destination file.

Parameters:
srcFilename - The path of the input pdf file.
desFilename - The path of the output pdf file.
Throws:
java.lang.Exception - On error.

FormEditor

public FormEditor(java.lang.String srcFilename,
                  java.io.OutputStream dstStream)
           throws java.lang.Exception
Represents a constructor of the FormEditor object with source file and destination stream.

Parameters:
srcFilename - The path of the input pdf file.
dstStream - The path of the output stream.
Throws:
java.lang.Exception - On error.

FormEditor

public FormEditor(java.io.InputStream srcStream,
                  java.io.OutputStream dstStream)
           throws java.lang.Exception
Represents a constructor of the FormEditor object with source stream and destination stream.

Parameters:
srcStream - The path of the input stream.
dstStream - The path of the output stream.
Throws:
java.lang.Exception - On error.

FormEditor

public FormEditor(java.io.InputStream srcStream,
                  java.lang.String desFilename)
           throws java.lang.Exception
Represents a constructor of the FormEditor object with source stream and destination file.

Parameters:
srcStream - The path of the input stream.
desFilename - The path of the pdf file.
Throws:
java.lang.Exception - On error.
Method Detail

setItems

public void setItems(java.lang.String[] mItems)
Set items for combo box/list/radio box fields creation.

Parameters:
mItems - An array of string, each representing an option of a combo box/list/radio box field.

setRadioHoriz

public void setRadioHoriz(boolean radioHoriz)
Setter of radioHoriz.

Parameters:
radioHoriz - Specify the arranging style of radios, true for horizontal and false for vertical.

setRadioGap

public void setRadioGap(float radioGap)
Setter of radioGap.

Parameters:
radioGap - Specify the distance in pixel between two neighbor radio buttons.

resetFacade

public void resetFacade()
Reset all visual attributes to default values.


close

public void close()
           throws java.lang.Exception
Saves all the modifications and closes the destination file.

Throws:
java.lang.Exception - On closing error.

decorateField

public void decorateField()
                   throws java.lang.Exception
Change visual attributes of all fields.

Throws:
java.lang.Exception - On errors.

decorateField

public void decorateField(int fieldType)
                   throws java.lang.Exception
Change visual attributes of all fields with the same field type.

Parameters:
fieldType - Field type of FormField.FLDTYP_*.
Throws:
java.lang.Exception - On errors.

decorateField

public void decorateField(java.lang.String fieldName)
                   throws java.lang.Exception
Change visual attributes of the specified field.

Parameters:
fieldName - The fully qualified field name.
Throws:
java.lang.Exception - On errers.

setFieldAttr

public void setFieldAttr(java.lang.String fieldName,
                         int flag)
                  throws java.lang.Exception
Throws:
java.lang.Exception

setFieldFlag

public void setFieldFlag(java.lang.String fieldName,
                         int flag)
                  throws java.lang.Exception
Sets the field's appearance flags, including displayed, printed, zoomed, or rotated.

Parameters:
fieldName - The fully qualified field name.
flag - The appearance flag to be set, must be Form.FLAG_*.
Throws:
java.lang.Exception - On error.

moveTo

public void moveTo(java.lang.String fieldName,
                   float llx,
                   float lly,
                   float urx,
                   float ury)
            throws java.lang.Exception
Moves the field to a new position specifying by a couple of vertexs.

Parameters:
fieldName - The fully qualified field name.
llx - The abscissa of the field's low left vertex.
lly - The ordinate of the field's low left vertex.
urx - The abscissa of the field's up right vertex.
ury - The ordinate of the field's up right vertex.
Throws:
java.lang.Exception - On error.

moveTo

public void moveTo(java.lang.String fieldName,
                   float right,
                   float up)
            throws java.lang.Exception
Moves the field to a new position specifying by relative offsets.

Parameters:
fieldName - The fully qualified field name.
right - The relative offset of abscissa, positive referring to move right, and negative referring to move left.
up - The relative offset of ordinate, positive referring to move up, and negative referring to move down.
Throws:
java.lang.Exception - On error.

zoom

public void zoom(java.lang.String fieldName,
                 float scaleLength,
                 float scaleWidth)
          throws java.lang.Exception
Zooms the field according to the specific scales. The outcoming may be disproportionate if scaleLength doesn't match scaleWidth.

Parameters:
fieldName - The fully qualified field name.
scaleLength - The scale for length zooming only, must be positive.
scaleWidth - The scale for width zooming only, must be positive.
Throws:
java.lang.Exception - On error.

zoom

public void zoom(java.lang.String fieldName,
                 float scale)
          throws java.lang.Exception
Zooms the field proportionately according to the specific scale.

Parameters:
fieldName - The fully qualified field name.
scale - The scale to zoom, both for the length and width.
Throws:
java.lang.Exception - On error.

setSubmitBtnUrl

public void setSubmitBtnUrl(java.lang.String fieldName,
                            java.lang.String url)
                     throws java.lang.Exception
Sets the url destination of a filed, only effective to submit buttons.

Parameters:
fieldName - The fully qualified field name.
url - The destination to be assigned.
Throws:
java.lang.Exception - On error.

addField

public void addField(int fieldType,
                     java.lang.String fieldName,
                     java.lang.String value,
                     int pageNum,
                     java.awt.Rectangle rect)
              throws java.lang.Exception
Insert a specified field into existing PDF document at corresponding position.

Parameters:
fieldType - The type of field adding, must be FormEditor.FLDTYP_*.
fieldName - The fully qualified field name.
pageNum - The page number that field will be inserted into.
rect - The Rectangle specifying a position to hold the new field.
Throws:
java.lang.Exception - On adding errors.

removeField

public void removeField(java.lang.String fieldName)
Remove a field specified by fieldName.

Parameters:
fieldName - The fully qualified field name.

renameField

public void renameField(java.lang.String fieldName,
                        java.lang.String newFieldName)
Change a field's name.

Parameters:
fieldName - The old fully qualified field name.
newFieldName - The new fully qualified field name.

localCopyField

public void localCopyField(java.lang.String fieldName,
                           java.lang.String newFieldName,
                           int pageNum)
                    throws PdfKitException,
                           java.lang.Exception
Copy an existing field from current page to another page in the same position. A new document will be produced, which contains everything the source document has except for the newly copied field.

Parameters:
fieldName - The old fully qualified field name.
newFieldName - The new fully qualified field name. If null, it will be set as fieldName + "~".
pageNum - The number of page to hold the new field. If zero, new field will be copid to the same page as old one hosted.
Throws:
PdfKitException - On errors.
java.lang.Exception - On errors.

localCopyField

public void localCopyField(java.lang.String fieldName,
                           java.lang.String newFieldName,
                           int pageNum,
                           float abscissa,
                           float ordinate)
                    throws PdfKitException,
                           java.lang.Exception
Copies an existing field to a new position pecified by page number and ordinates. A new document will be produced, which contains everything the source document has except for the newly copied field.

Parameters:
fieldName - The old fully qualified field name.
newFieldName - The new fully qualified field name. If null, it will be set as fieldName + "~".
pageNum - The number of page to hold the new field. If zero, new field will be copid to the same page as old one hosted.
abscissa - The abscissa of the new field.
ordinate - The ordinate of the new field.
Throws:
PdfKitException - On errors.
java.lang.Exception - On errors.

setFacade

public void setFacade(FormFieldFacade facade)
Setter of member facade.

Parameters:
facade -