Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class Form

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

public class Form
extends java.lang.Object

Represents a class which is used to modify AcroForms Field in existing pdf documents. Various form fields can be easily modified or flattened with APIs, including: -text field -list box field -combo box field -radio button box field -check box field Additionally, image button field can be filled with a specified image. It can be used like this:

     //Open the document and create a Form object like this:
     Form form = new Form("Online.pdf", "output.pdf");
     //Add a logo field at the top of each page like this:
     form.setWaterMark("newwatermark.jpg");
     //Fill a text field like this:
     form.setField("fullName", "Luke Fu");
     //Select a  radio button like this:
     form.setField("gender", "male");
     //Paste a image onto the existing button field like this:
     form.fillImageField("photo", "watermark.jpg");
     //Choose a item from a combe box field like this:
     form.setField("bankList", "list Item3");
     //Choose a item from a list field like this:
     form.setField("period", "1 year");
     //Select a  ckeck box like this:
     form.setField("pay", "Yes");

     //Flatten all the fields like this:
     //form.allFlatten();

     //Close the document like this:
     form.close();
 


Field Summary
static int ATTR_NO_EXPORT
          If set, the field must not be exported by a submit-form action.
static int ATTR_READ_ONLY
          If set, the user may not change the value of the field.
static int ATTR_REQUIRED
          If set, this field must have a value at the time it is exported by a submit-form field, otherwise errors will occur.
static int FLAG_HIDDEN
          If set, do not display or print the field or allow it to interact with the user.
static int FLAG_LOCKED
          If set, lock the field, not allowing it to be deleted or its properties to be modified by the user, such as position and size.
static int FLAG_NOROTATE
          If set, do not rotate the fieldĄ¯s appearance to match the rotation of the page.
static int FLAG_NOVIEW
          If set, do not display the field on the screen or allow it to interact with the user.
static int FLAG_NOZOOM
          If set, do not scale the fieldĄ¯s appearance to match the magnification of the page.
static int FLAG_PRINT
          If set, print the field when the page is printed.
static int FLAG_READONLY
          If set, do not allow the field to interact with the user.
static int FLAG_TOGGLENOVIEW
          If set, invert the interpretation of the NoView flag for certain events.
 
Constructor Summary
Form()
          Represents a constructor of the Form object without any parameter
Form(java.io.InputStream srcStream, java.io.OutputStream dstStream)
          Represents a constructor of the Form object with source stream and destination stream.
Form(java.io.InputStream srcStream, java.lang.String desFilename)
          Represents a constructor of the Form object with source stream and destination file.
Form(java.lang.String srcFilename)
          Represents a constructor of the Form object with only a source file.
Form(java.lang.String srcFilename, java.io.OutputStream dstStream)
          Represents a constructor of the Form object with source file and destination stream.
Form(java.lang.String srcFilename, java.lang.String desFilename)
          Represents a constructor of the Form object with source file and destination file.
 
Method Summary
 void allFlatten()
          Flattens all fields in the specified pdf document.
 void close()
          Saves all the modifications and closes the destination file.
 void exportFdf(java.lang.String pdfFilename, java.io.OutputStream fdfStream)
          Exports the content of the fields in source PDF into a FDF stream.
 void exportFdf(java.lang.String pdfFilename, java.lang.String fdfFilename)
          Exports the content of the fields in PDF into a FDF file.
 void exportXfdf(java.lang.String pdfFilename, java.io.OutputStream xfdfOutputStream)
          Exports the content of the fields in PDF into a XFDF stream.
 void exportXfdf(java.lang.String pdfFilename, java.lang.String xfdfFilename)
          Exports the content of the fields in PDF into a XFDF file.
 void exportXml(java.io.OutputStream xmlOutputStream)
          Export field information to a standard XML stream.
 void exportXml(java.lang.String xmlOutputFile)
          Export field information to a standard XML file.
 void fillImageField(java.lang.String fieldName, java.lang.String imageFilename)
          Pastes an image onto the existing button field as its appearance.
 java.lang.String[] getFieldsNames()
          Gets the names of all the fields contained in the PDF document.
 int getFieldType(java.lang.String fieldName)
          The getter of the type of the specified field.
 java.lang.String getFieldValue(java.lang.String fieldName)
          Gets the field's value according to its field name.
 java.io.OutputStream getOutputStream()
          The getter of the output stream member.
 void importFdf(java.io.InputStream fdfStream)
          Imports the content of fields from a FDF stream into a PDF template to generate a new PDF document.
 void importFdf(java.lang.String fdfFilename)
          Imports the content of fields from a FDF file into a PDF template to generate a new PDF document.
 void importXfdf(java.io.InputStream xfdfInputStream)
          Imports the content of fields from a XFDF stream into a PDF template to generate a new PDF document.
 void importXfdf(java.lang.String xfdfFilename)
          Imports the content of fields from a XFDF stream into a PDF template to generate a new PDF document.
 void importXml(java.io.InputStream xmlInputStream)
          Import information from a standard XML stream to a PDF template, producing a PDF document.
 void importXml(java.lang.String xmlInputFile)
          Import information from a standard XML file to a PDF template, producing a PDF document.
 void moveTo(java.lang.String fieldName, float right, float up)
          Deprecated.
 void moveTo(java.lang.String fieldName, float llx, float lly, float urx, float ury)
          Deprecated.
 void partialFlatten(java.lang.String fieldName)
          Flattens part of the fields set in the specified pdf document.
 void setField(java.lang.String fieldName, java.lang.String value)
          Modifies the value of an existing field according to a specified field name.
 void setFieldAttr(java.lang.String fieldName, int flag)
          Deprecated.
 void setFieldFlag(java.lang.String fieldName, int flag)
          Deprecated.
 void setSubmitBtnUrl(java.lang.String fieldName, java.lang.String url)
          Deprecated.
 void setWaterMark(java.lang.String imageFilename)
          Inserts an appointed watermark or logo field at the top of the pdf document.
 void zoom(java.lang.String fieldName, float scale)
          Deprecated.
 void zoom(java.lang.String fieldName, float scaleLength, float scaleWidth)
          Deprecated.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_HIDDEN

public static final int FLAG_HIDDEN
If set, do not display or print the field or allow it to interact with the user.

See Also:
Constant Field Values

FLAG_PRINT

public static final int FLAG_PRINT
If set, print the field when the page is printed.

See Also:
Constant Field Values

FLAG_NOZOOM

public static final int FLAG_NOZOOM
If set, do not scale the fieldĄ¯s appearance to match the magnification of the page.

See Also:
Constant Field Values

FLAG_NOROTATE

public static final int FLAG_NOROTATE
If set, do not rotate the fieldĄ¯s appearance to match the rotation of the page.

See Also:
Constant Field Values

FLAG_NOVIEW

public static final int FLAG_NOVIEW
If set, do not display the field on the screen or allow it to interact with the user.

See Also:
Constant Field Values

FLAG_READONLY

public static final int FLAG_READONLY
If set, do not allow the field to interact with the user.

See Also:
Constant Field Values

FLAG_LOCKED

public static final int FLAG_LOCKED
If set, lock the field, not allowing it to be deleted or its properties to be modified by the user, such as position and size.

See Also:
Constant Field Values

FLAG_TOGGLENOVIEW

public static final int FLAG_TOGGLENOVIEW
If set, invert the interpretation of the NoView flag for certain events.

See Also:
Constant Field Values

ATTR_READ_ONLY

public static final int ATTR_READ_ONLY
If set, the user may not change the value of the field. This flag is useful for fields whose values are computed or imported from a database.

See Also:
Constant Field Values

ATTR_REQUIRED

public static final int ATTR_REQUIRED
If set, this field must have a value at the time it is exported by a submit-form field, otherwise errors will occur.

See Also:
Constant Field Values

ATTR_NO_EXPORT

public static final int ATTR_NO_EXPORT
If set, the field must not be exported by a submit-form action.

See Also:
Constant Field Values
Constructor Detail

Form

public Form()
     throws java.lang.Exception
Represents a constructor of the Form object without any parameter

Throws:
java.lang.Exception - On errers.

Form

public Form(java.lang.String srcFilename)
     throws java.lang.Exception
Represents a constructor of the Form object with only a source file.

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

Form

public Form(java.lang.String srcFilename,
            java.lang.String desFilename)
     throws java.lang.Exception
Represents a constructor of the Form 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.

Form

public Form(java.lang.String srcFilename,
            java.io.OutputStream dstStream)
     throws java.lang.Exception
Represents a constructor of the Form 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.

Form

public Form(java.io.InputStream srcStream,
            java.io.OutputStream dstStream)
     throws java.lang.Exception
Represents a constructor of the Form 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.

Form

public Form(java.io.InputStream srcStream,
            java.lang.String desFilename)
     throws java.lang.Exception
Represents a constructor of the Form 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

setField

public void setField(java.lang.String fieldName,
                     java.lang.String value)
              throws java.lang.Exception
Modifies the value of an existing field according to a specified field name.

Parameters:
fieldName - The fully qualified field name.
value - The value to be appointed.
Throws:
java.lang.Exception

setSubmitBtnUrl

public void setSubmitBtnUrl(java.lang.String fieldName,
                            java.lang.String url)
                     throws java.lang.Exception
Deprecated. Please refer to FormEditor.setSubmitBtnUrl(). 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.

setFieldFlag

public void setFieldFlag(java.lang.String fieldName,
                         int flag)
                  throws java.lang.Exception
Deprecated. Please refer to FormEditor.setFieldFlag(). 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.

setFieldAttr

public void setFieldAttr(java.lang.String fieldName,
                         int flag)
                  throws java.lang.Exception
Deprecated. Please refer to FormEditor.setFieldAttr(). Set the field's exporting attributes, including ATTR_READ_ONLY, ATTR_REQUIRED and ATTR_NO_EXPORT.

Parameters:
fieldName - The fully qualified field name.
flag - The attribute flag to be set, must be Form.ATTR_*.
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
Deprecated. Please refer to FormEditor.moveTo(). 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
Deprecated. Please refer to FormEditor.moveTo(). 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
Deprecated. Please refer to FormEditor.zoom(). 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
Deprecated. Please refer to FormEditor.zoom(). 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.

partialFlatten

public void partialFlatten(java.lang.String fieldName)
                    throws java.lang.Exception
Flattens part of the fields set in the specified pdf document.

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

allFlatten

public void allFlatten()
                throws java.lang.Exception
Flattens all fields in the specified pdf document.

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

close

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

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

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.lang.Exception
The getter of the output stream member.

Returns:
The output stream.
Throws:
java.lang.Exception - On error.

getFieldType

public int getFieldType(java.lang.String fieldName)
The getter of the type of the specified field.

Parameters:
fieldName - The fully qualified field name.
Returns:
An int value of the field type.

getFieldsNames

public java.lang.String[] getFieldsNames()
Gets the names of all the fields contained in the PDF document.

Returns:
A String set which containes all the fields' names. If no field is contained, it will return a null.

getFieldValue

public java.lang.String getFieldValue(java.lang.String fieldName)
Gets the field's value according to its field name.

Parameters:
fieldName - The fully qualified field name.
Returns:
The value of the specified field.

fillImageField

public void fillImageField(java.lang.String fieldName,
                           java.lang.String imageFilename)
                    throws PdfKitException,
                           java.io.IOException
Pastes an image onto the existing button field as its appearance.

Parameters:
fieldName - The fully qualified field name of the image button field.
imageFilename - The path of the image file, relative and absolute are both ok.
Throws:
PdfKitException
java.io.IOException

setWaterMark

public void setWaterMark(java.lang.String imageFilename)
                  throws java.net.MalformedURLException,
                         java.io.IOException,
                         com.aspose.pdf.kit.BadElementException,
                         PdfKitException
Inserts an appointed watermark or logo field at the top of the pdf document. These fields should be flattened manually.

Parameters:
imageFilename - The path of the watermark image or logo file, relative and absolute are both ok.
Throws:
java.net.MalformedURLException
java.io.IOException
com.aspose.pdf.kit.BadElementException
PdfKitException

exportFdf

public void exportFdf(java.lang.String pdfFilename,
                      java.io.OutputStream fdfStream)
               throws java.lang.Exception
Exports the content of the fields in source PDF into a FDF stream.

Parameters:
pdfFilename - the name of the PDF document.
fdfStream - the name of the destination FDF stream.
Throws:
java.lang.Exception - On export error.

exportFdf

public void exportFdf(java.lang.String pdfFilename,
                      java.lang.String fdfFilename)
               throws java.lang.Exception
Exports the content of the fields in PDF into a FDF file.

Parameters:
pdfFilename - the name of the source PDF document.
fdfFilename - the name of the destination FDF file.
Throws:
java.lang.Exception - On export error.

importFdf

public void importFdf(java.io.InputStream fdfStream)
               throws PdfKitException,
                      java.io.IOException
Imports the content of fields from a FDF stream into a PDF template to generate a new PDF document.

Parameters:
fdfStream - the name of the source FDF stream.
Throws:
PdfKitException - On error.
java.io.IOException - On error.

importFdf

public void importFdf(java.lang.String fdfFilename)
               throws PdfKitException,
                      java.io.IOException
Imports the content of fields from a FDF file into a PDF template to generate a new PDF document.

Parameters:
fdfFilename - the name of the source FDF file.
Throws:
PdfKitException - On error.
java.io.IOException - On error.

exportXfdf

public void exportXfdf(java.lang.String pdfFilename,
                       java.lang.String xfdfFilename)
                throws java.lang.Exception
Exports the content of the fields in PDF into a XFDF file.

Parameters:
pdfFilename - the name of the source PDF document.
xfdfFilename - the name of the destination XFDF file.
Throws:
java.lang.Exception - On export error.

exportXfdf

public void exportXfdf(java.lang.String pdfFilename,
                       java.io.OutputStream xfdfOutputStream)
                throws java.lang.Exception
Exports the content of the fields in PDF into a XFDF stream.

Parameters:
pdfFilename - the name of the source PDF document.
xfdfOutputStream - the name of the destination XFDF stream.
Throws:
java.lang.Exception - On export error.

importXfdf

public void importXfdf(java.lang.String xfdfFilename)
                throws java.lang.Exception
Imports the content of fields from a XFDF stream into a PDF template to generate a new PDF document.

Parameters:
xfdfFilename - the name of the source XFDF file.
Throws:
java.lang.Exception - On import error.

importXfdf

public void importXfdf(java.io.InputStream xfdfInputStream)
                throws java.lang.Exception
Imports the content of fields from a XFDF stream into a PDF template to generate a new PDF document.

Parameters:
xfdfInputStream - the name of the source XFDF file.
Throws:
java.lang.Exception - On import error.

importXml

public void importXml(java.lang.String xmlInputFile)
               throws java.lang.Exception
Import information from a standard XML file to a PDF template, producing a PDF document.

Parameters:
xmlInputFile - the name of the input XML file.
Throws:
java.lang.Exception - On errors.

importXml

public void importXml(java.io.InputStream xmlInputStream)
               throws java.lang.Exception
Import information from a standard XML stream to a PDF template, producing a PDF document.

Parameters:
xmlInputStream - the name of the input XML stream.
Throws:
java.lang.Exception - On errors.

exportXml

public void exportXml(java.lang.String xmlOutputFile)
               throws java.lang.Exception
Export field information to a standard XML file.

Parameters:
xmlOutputFile - the name of the output XML file document.
Throws:
java.lang.Exception - On errers.

exportXml

public void exportXml(java.io.OutputStream xmlOutputStream)
               throws java.lang.Exception
Export field information to a standard XML stream.

Parameters:
xmlOutputStream - the name of the output XML stream.
Throws:
java.lang.Exception - On errors.