com.qoppa.pdfFields
Class PDFFields

java.lang.Object
  extended bycom.qoppa.pdfFields.PDFFields

public class PDFFields
extends Object

The PDFFields class provides methods to work with interactive PDF forms - also called acroforms.
It can load an existing PDF form and extract acroform fields in XML (XFDF) or FDF format.
It can also load an existing PDF form and import acroform fields from an XML (XFDF) or FDF file and then save the updated PDF form.

Author:
Qoppa Software

Constructor Summary
PDFFields(InputStream inStream, IPassword password)
          Loads a PDF document from an InputStream.
PDFFields(String fileName, IPassword password)
          Loads a PDF document from a file.
PDFFields(URL url, IPassword password)
          Loads a PDF document from a URL.
 
Method Summary
 void exportAsFDF(OutputStream outStream, String pathToPDFFile, boolean exportEmptyFields)
          Export AcroForm field data to an output stream in FDF format.
 void exportAsFDF(String fileName, boolean exportEmptyFields)
          Exports AcroForm field data to a file in FDF format.
 void exportAsXDP(OutputStream outStream, String pathToPDFFile, boolean exportEmptyFields)
          Export XFA field data to an output stream in XDP format.
 void exportAsXDP(String fileName, boolean exportEmptyFields)
          Exports XFA field data to a file in XDP format.
 void exportAsXFDF(OutputStream outStream, String pathToPDFFile, boolean exportEmptyFields)
          Export AcroForm field data to an output stream in XFDF format.
 void exportAsXFDF(String fileName, boolean exportEmptyFields)
          Exports AcroForm field data to a file in XML format.
 void flattenFields(boolean paintButtons, boolean paintNonPrintableFields)
          Flattens the form fields in the current PDF document.
 DocumentInfo getDocumentInfo()
          Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)
 FormField getField(String fieldName)
          Gets a field by name.
 Vector getFieldList()
          Gets the list of fields in this AcroForm.
static String getVersion()
          Returns version string for jPDFFields.
 void importFDF(InputStream inStream)
          Import AcroForm field data from an input stream in FDF format.
 void importFDF(String fileName)
          Import Acroform field data from a file in FDF Format.
 void importXDP(InputStream inStream)
          Import XFA field data from an input stream in XDP format.
 void importXDP(String fileName)
          Import XFA field data from a file in XDP Format.
 void importXFDF(InputStream inStream)
          Import AcroForm field data from an input stream in XML format.
 void importXFDF(String fileName)
          Import Acroform fields data from a file in XML Format.
 void resetFields()
          Reset fields values to their default value.
 void saveDocument(OutputStream outStream)
          Saves this document to an output stream.
 void saveDocument(String fileName)
          Saves this document to a file.
static void setAppletKey(String key, Applet applet)
          Method to unlock the production version of the library.
static boolean setKey(String key)
          Method to unlock the production version of the library.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFFields

public PDFFields(InputStream inStream,
                 IPassword password)
          throws PDFException
Loads a PDF document from an InputStream.

Parameters:
inStream - InputStream to read the PDF document.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.

PDFFields

public PDFFields(String fileName,
                 IPassword password)
          throws PDFException
Loads a PDF document from a file.

Parameters:
fileName - Name of the PDF file.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.

PDFFields

public PDFFields(URL url,
                 IPassword password)
          throws PDFException
Loads a PDF document from a URL.

Parameters:
url - Location of the PDF document.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.
Method Detail

getDocumentInfo

public DocumentInfo getDocumentInfo()
Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)

Returns:
DocumentInfo Object containing header information for the document.

getVersion

public static String getVersion()
Returns version string for jPDFFields. If this is the demo version, the return string will contain 'Demo Version' at the end.


exportAsFDF

public void exportAsFDF(OutputStream outStream,
                        String pathToPDFFile,
                        boolean exportEmptyFields)
                 throws PDFException,
                        IOException
Export AcroForm field data to an output stream in FDF format.

Parameters:
outStream - The output stream to write the data to.
pathToPDFFile - is the relative path from the fdf file to the pdf file name. This parameter can be left null. This parameter is used to fill the pdf file name entry in the FDF file, the file entry will be set to pathToPDFFile + fileNa The file entry is used when you open an fdf file to be able to locate the corresponding pdf file.
exportEmptyFields - flag to indicate whether empty or null fields should be exported. Example of pathToPDFFile ../qoppa/mydir
Throws:
PDFException
IOException

exportAsFDF

public void exportAsFDF(String fileName,
                        boolean exportEmptyFields)
                 throws PDFException,
                        IOException
Exports AcroForm field data to a file in FDF format.

Parameters:
fileName - The name of the file to export the data to.
exportEmptyFields - flag to indicate whether empty or null fields should be exported.
Throws:
PDFException
IOException

exportAsXFDF

public void exportAsXFDF(OutputStream outStream,
                         String pathToPDFFile,
                         boolean exportEmptyFields)
                  throws PDFException
Export AcroForm field data to an output stream in XFDF format.

Parameters:
outStream - The output stream to write the data to.
pathToPDFFile - is the relative path from the fdf file to the pdf file name. This parameter can be left null. This parameter is used to fill the pdf file name entry in the FDF file, the file entry will be set to pathToPDFFile + fileNa The file entry is used when you open an fdf file to be able to locate the corresponding pdf file. Example of pathToPDFFile ../qoppa/mydir
exportEmptyFields - flag to indicate whether empty or null fields should be exported.
Throws:
PDFException

exportAsXFDF

public void exportAsXFDF(String fileName,
                         boolean exportEmptyFields)
                  throws PDFException
Exports AcroForm field data to a file in XML format.

Parameters:
fileName - The name of the file to export the data to.
exportEmptyFields - flag to indicate whether empty or null fields should be exported.
Throws:
IOException
PDFException

exportAsXDP

public void exportAsXDP(String fileName,
                        boolean exportEmptyFields)
                 throws IOException,
                        PDFException
Exports XFA field data to a file in XDP format.

Parameters:
fileName - The name of the file to export the data to.
exportEmptyFields - flag to indicate whether empty or null fields should be exported.
Throws:
IOException - If there are any errors opening or writing to the file.
PDFException If there is no no XFA form defined in the PDF document.
PDFException

exportAsXDP

public void exportAsXDP(OutputStream outStream,
                        String pathToPDFFile,
                        boolean exportEmptyFields)
                 throws IOException,
                        PDFException
Export XFA field data to an output stream in XDP format.

Parameters:
outStream - The output stream to write the data to.
pathToPDFFile - is the relative path from the xdp file to the pdf file name. This parameter can be left null. This parameter is used to fill the pdf file name reference in the XDP file, the file entry will be set to pathToPDFFile + fileName
exportEmptyFields - flag to indicate whether empty or null fields should be exported.

Example of pathToPDFFile ../qoppa/mydir
Throws:
IOException - If there are any errors writing to the output stream.
PDFException If there is no no XFA form defined in the PDF document.
PDFException

flattenFields

public void flattenFields(boolean paintButtons,
                          boolean paintNonPrintableFields)
                   throws PDFException
Flattens the form fields in the current PDF document. This method paints the content of the fields directly into the pages and remove the fields themselves from the document.

Parameters:
paintButtons - Flag to indicate whether push buttons should be painted or not.
paintNonPrintableFields - Flag to indicate whether non-printable fields should be painted or not.
Throws:
PDFException

getFieldList

public Vector getFieldList()
Gets the list of fields in this AcroForm. The objects in the returned Vector are of type FormField.

Returns:
A Vector of FormField objects.

getField

public FormField getField(String fieldName)
Gets a field by name. As fields can be hierarchical, names of fields can be hierarchical: choices.choice1 would refer to a field named choice1 whose parent is a field named choices.

Parameters:
fieldName - The name of a field in hierarchical form.
Returns:
AFField The field referenced by the name, null if there is no field by that name.

importFDF

public void importFDF(InputStream inStream)
               throws PDFException
Import AcroForm field data from an input stream in FDF format.

Parameters:
inStream - The input stream in FDF format to read the data from.
Throws:
PDFException

importFDF

public void importFDF(String fileName)
               throws PDFException
Import Acroform field data from a file in FDF Format.

Parameters:
fileName - The name of the FDF file to import the data from.
Throws:
PDFException

importXFDF

public void importXFDF(InputStream inStream)
                throws PDFException
Import AcroForm field data from an input stream in XML format.

Parameters:
inStream - The input stream in XML format to read the data from.
Throws:
PDFException

importXDP

public void importXDP(String fileName)
               throws PDFException,
                      IOException
Import XFA field data from a file in XDP Format.

Parameters:
fileName - The name of the XDP file to import the data from.
Throws:
PDFException, - IOException
PDFException
IOException

importXDP

public void importXDP(InputStream inStream)
               throws PDFException,
                      IOException
Import XFA field data from an input stream in XDP format.

Parameters:
inStream - The input stream in XDP format to read the data from. throws PDFException, IOException
Throws:
PDFException
IOException

importXFDF

public void importXFDF(String fileName)
                throws PDFException
Import Acroform fields data from a file in XML Format.

Parameters:
fileName - The name of the XML file to import the data from.
Throws:
PDFException

resetFields

public void resetFields()
                 throws PDFException
Reset fields values to their default value. If there is no default values, then value is set to null.

Throws:
PDFException

saveDocument

public void saveDocument(String fileName)
                  throws IOException,
                         PDFException
Saves this document to a file.

Parameters:
fileName - Name of the file to save the document.
Throws:
IOException
PDFException

saveDocument

public void saveDocument(OutputStream outStream)
                  throws IOException,
                         PDFException
Saves this document to an output stream.

Parameters:
outStream - OutputStream where the document will be written to.
Throws:
IOException
PDFException

setAppletKey

public static void setAppletKey(String key,
                                Applet applet)
Method to unlock the production version of the library.

Parameters:
key - Production key.

setKey

public static boolean setKey(String key)
Method to unlock the production version of the library.

Parameters:
key - Production key.