Class XfaForm

java.lang.Object
com.itextpdf.forms.xfa.XfaForm

public class XfaForm extends Object
Processes XFA forms.
  • Field Details

  • Constructor Details

    • XfaForm

      public XfaForm()
      An empty constructor to build on.
    • XfaForm

      public XfaForm (InputStream inputStream)
      Creates an XFA form by the stream containing all xml information
      Parameters:
      inputStream - the InputStream
    • XfaForm

      public XfaForm (Document domDocument)
      Creates an XFA form by the Document containing all xml information
      Parameters:
      domDocument - The document
    • XfaForm

      public XfaForm (PdfDictionary acroFormDictionary)
      A constructor from a PdfDictionary. It is assumed, but not necessary for correct initialization, that the dictionary is actually a PdfAcroForm. An entry in the dictionary with the XFA key must contain correct XFA syntax. If the XFA key is absent, then the constructor essentially does nothing.
      Parameters:
      acroFormDictionary - the dictionary object to initialize from
    • XfaForm

      public XfaForm (PdfDocument pdfDocument)
      A constructor from a PdfDocument. It basically does everything from finding the XFA stream to the XML parsing.
      Parameters:
      pdfDocument - the PdfDocument instance
  • Method Details

    • setXfaForm

      public static void setXfaForm (XfaForm form, PdfDocument pdfDocument) throws IOException
      Sets the XFA key from a byte array. The old XFA is erased.
      Parameters:
      form - the data
      pdfDocument - pdfDocument
      Throws:
      IOException - if any I/O issue occurs
    • setXfaForm

      public static void setXfaForm (XfaForm form, PdfAcroForm acroForm) throws IOException
      Sets the XFA key from a byte array. The old XFA is erased.
      Parameters:
      form - the data
      acroForm - an PdfAcroForm instance
      Throws:
      IOException - if any I/O issue occurs
    • extractXFANodes

      public static Map<String,Node> extractXFANodes (Document domDocument)
      Extracts DOM nodes from an XFA document.
      Parameters:
      domDocument - an XFA file as a DOM document
      Returns:
      a Map of XFA packet names and their associated DOM nodes
    • write

      public void write (PdfDocument document) throws IOException
      Write the XfaForm to the provided PdfDocument.
      Parameters:
      document - the PdfDocument to write the XFA Form to
      Throws:
      IOException - if any I/O issue occurs
    • write

      public void write (PdfAcroForm acroForm) throws IOException
      Write the XfaForm to the provided PdfAcroForm.
      Parameters:
      acroForm - the PdfDocument to write the XFA Form to
      Throws:
      IOException - if any I/O issue occurs
    • setXfaFieldValue

      public void setXfaFieldValue (String name, String value)
      Changes a field value in the XFA form.
      Parameters:
      name - the name of the field to be changed
      value - the new value
    • getXfaFieldValue

      public String getXfaFieldValue (String name)
      Gets the xfa field value.
      Parameters:
      name - the fully qualified field name
      Returns:
      the field value
    • isXfaPresent

      public boolean isXfaPresent()
      Returns true if it is a XFA form.
      Returns:
      true if it is a XFA form
    • findFieldName

      public String findFieldName (String name)
      Finds the complete field name from a partial name.
      Parameters:
      name - the complete or partial name
      Returns:
      the complete name or null if not found
    • findDatasetsName

      public String findDatasetsName (String name)
      Finds the complete SOM name contained in the datasets section from a possibly partial name.
      Parameters:
      name - the complete or partial name
      Returns:
      the complete name or null if not found
    • findDatasetsNode

      public Node findDatasetsNode (String name)
      Finds the Node contained in the datasets section from a possibly partial name.
      Parameters:
      name - the complete or partial name
      Returns:
      the Node or null if not found
    • getNodeText

      public static String getNodeText (Node n)
      Gets all the text contained in the child nodes of this node.
      Parameters:
      n - the Node
      Returns:
      the text found or "" if no text was found
    • setNodeText

      public void setNodeText (Node n, String text)
      Sets the text of this node. All the child's node are deleted and a new child text node is created.
      Parameters:
      n - the Node to add the text to
      text - the text to add
    • getDomDocument

      public Document getDomDocument()
      Gets the top level DOM document.
      Returns:
      the top level DOM document
    • setDomDocument

      public void setDomDocument (Document domDocument)
      Sets the top DOM document.
      Parameters:
      domDocument - the top DOM document
    • getDatasetsNode

      public Node getDatasetsNode()
      Gets the Node that corresponds to the datasets part.
      Returns:
      the Node that corresponds to the datasets part
    • fillXfaForm

      public void fillXfaForm (File file) throws IOException
      Replaces the XFA data under datasets/data. Accepts a file object to fill this object with XFA data. The resulting DOM document may be modified.
      Parameters:
      file - the File
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (File file, boolean readOnly) throws IOException
      Replaces the XFA data under datasets/data. Accepts a file object to fill this object with XFA data.
      Parameters:
      file - the File
      readOnly - whether or not the resulting DOM document may be modified
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (InputStream is) throws IOException
      Replaces the XFA data under datasets/data. Accepts an InputStream to fill this object with XFA data. The resulting DOM document may be modified.
      Parameters:
      is - the InputStream
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (InputStream is, boolean readOnly) throws IOException
      Replaces the XFA data under datasets/data. Accepts an InputStream to fill this object with XFA data.
      Parameters:
      is - the InputStream
      readOnly - whether or not the resulting DOM document may be modified
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (InputSource is) throws IOException
      Replaces the XFA data under datasets/data. Accepts a SAX input source to fill this object with XFA data. The resulting DOM document may be modified.
      Parameters:
      is - the SAX input source
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (InputSource is, boolean readOnly) throws IOException
      Replaces the XFA data under datasets/data. Accepts a SAX input source to fill this object with XFA data.
      Parameters:
      is - the SAX input source
      readOnly - whether or not the resulting DOM document may be modified
      Throws:
      IOException - if any I/O issue occurs on the InputSource
    • fillXfaForm

      public void fillXfaForm (Node node)
      Replaces the XFA data under datasets/data.
      Parameters:
      node - the input Node
    • fillXfaForm

      public void fillXfaForm (Node node, boolean readOnly)
      Replaces the XFA data under datasets/data.
      Parameters:
      node - the input Node
      readOnly - whether or not the resulting DOM document may be modified