Package com.itextpdf.forms.xfa
Class XfaForm
java.lang.Object
com.itextpdf.forms.xfa.XfaForm
Processes XFA forms.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionXfaForm()
An empty constructor to build on.XfaForm
(PdfDictionary acroFormDictionary) A constructor from aPdfDictionary
.XfaForm
(PdfDocument pdfDocument) A constructor from aPdfDocument
.XfaForm
(InputStream inputStream) Creates an XFA form by the stream containing all xml informationCreates an XFA form by theDocument
containing all xml information -
Method Summary
Modifier and TypeMethodDescriptionextractXFANodes
(Document domDocument) Extracts DOM nodes from an XFA document.void
fillXfaForm
(File file) Replaces the XFA data under datasets/data.void
fillXfaForm
(File file, boolean readOnly) Replaces the XFA data under datasets/data.void
Replaces the XFA data under datasets/data.void
fillXfaForm
(InputStream is, boolean readOnly) Replaces the XFA data under datasets/data.void
fillXfaForm
(Node node) Replaces the XFA data under datasets/data.void
fillXfaForm
(Node node, boolean readOnly) Replaces the XFA data under datasets/data.void
Replaces the XFA data under datasets/data.void
fillXfaForm
(InputSource is, boolean readOnly) Replaces the XFA data under datasets/data.findDatasetsName
(String name) Finds the complete SOM name contained in the datasets section from a possibly partial name.findDatasetsNode
(String name) Finds theNode
contained in the datasets section from a possibly partial name.findFieldName
(String name) Finds the complete field name from a partial name.Gets theNode
that corresponds to the datasets part.Gets the top level DOM document.static String
getNodeText
(Node n) Gets all the text contained in the child nodes of this node.getXfaFieldValue
(String name) Gets the xfa field value.boolean
Returnstrue
if it is a XFA form.void
setDomDocument
(Document domDocument) Sets the top DOM document.void
setNodeText
(Node n, String text) Sets the text of this node.void
setXfaFieldValue
(String name, String value) Changes a field value in the XFA form.static void
setXfaForm
(XfaForm form, PdfAcroForm acroForm) Sets the XFA key from a byte array.static void
setXfaForm
(XfaForm form, PdfDocument pdfDocument) Sets the XFA key from a byte array.void
write
(PdfAcroForm acroForm) Write the XfaForm to the providedPdfAcroForm
.void
write
(PdfDocument document) Write the XfaForm to the providedPdfDocument
.
-
Field Details
-
XFA_DATA_SCHEMA
The URI for the XFA Data schema.- See Also:
-
-
Constructor Details
-
XfaForm
public XfaForm()An empty constructor to build on. -
XfaForm
Creates an XFA form by the stream containing all xml information- Parameters:
-
inputStream
- the InputStream
-
XfaForm
Creates an XFA form by theDocument
containing all xml information- Parameters:
-
domDocument
- The document
-
XfaForm
A constructor from aPdfDictionary
. It is assumed, but not necessary for correct initialization, that the dictionary is actually aPdfAcroForm
. An entry in the dictionary with theXFA
key must contain correct XFA syntax. If theXFA
key is absent, then the constructor essentially does nothing.- Parameters:
-
acroFormDictionary
- the dictionary object to initialize from
-
XfaForm
A constructor from aPdfDocument
. It basically does everything from finding the XFA stream to the XML parsing.- Parameters:
-
pdfDocument
- the PdfDocument instance
-
-
Method Details
-
setXfaForm
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
Sets the XFA key from a byte array. The old XFA is erased.- Parameters:
-
form
- the data -
acroForm
- anPdfAcroForm
instance - Throws:
-
IOException
- if any I/O issue occurs
-
extractXFANodes
Extracts DOM nodes from an XFA document.- Parameters:
-
domDocument
- an XFA file as aDOM document
- Returns:
-
a
Map
of XFA packet names and their associatedDOM nodes
-
write
Write the XfaForm to the providedPdfDocument
.- Parameters:
-
document
- the PdfDocument to write the XFA Form to - Throws:
-
IOException
- if any I/O issue occurs
-
write
Write the XfaForm to the providedPdfAcroForm
.- Parameters:
-
acroForm
- the PdfDocument to write the XFA Form to - Throws:
-
IOException
- if any I/O issue occurs
-
setXfaFieldValue
Changes a field value in the XFA form.- Parameters:
-
name
- the name of the field to be changed -
value
- the new value
-
getXfaFieldValue
Gets the xfa field value.- Parameters:
-
name
- the fully qualified field name - Returns:
- the field value
-
isXfaPresent
public boolean isXfaPresent()Returnstrue
if it is a XFA form.- Returns:
-
true
if it is a XFA form
-
findFieldName
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
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
Finds theNode
contained in the datasets section from a possibly partial name.- Parameters:
-
name
- the complete or partial name - Returns:
-
the
Node
ornull
if not found
-
getNodeText
Gets all the text contained in the child nodes of this node.- Parameters:
-
n
- theNode
- Returns:
- the text found or "" if no text was found
-
setNodeText
Sets the text of this node. All the child's node are deleted and a new child text node is created.- Parameters:
-
n
- theNode
to add the text to -
text
- the text to add
-
getDomDocument
Gets the top level DOM document.- Returns:
- the top level DOM document
-
setDomDocument
Sets the top DOM document.- Parameters:
-
domDocument
- the top DOM document
-
getDatasetsNode
Gets theNode
that corresponds to the datasets part.- Returns:
-
the
Node
that corresponds to the datasets part
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts afile object
to fill this object with XFA data. The resulting DOM document may be modified.- Parameters:
-
file
- theFile
- Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts afile object
to fill this object with XFA data.- Parameters:
-
file
- theFile
-
readOnly
- whether or not the resulting DOM document may be modified - Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts anInputStream
to fill this object with XFA data. The resulting DOM document may be modified.- Parameters:
-
is
- theInputStream
- Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts anInputStream
to fill this object with XFA data.- Parameters:
-
is
- theInputStream
-
readOnly
- whether or not the resulting DOM document may be modified - Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts aSAX input source
to fill this object with XFA data. The resulting DOM document may be modified.- Parameters:
-
is
- theSAX input source
- Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts aSAX input source
to fill this object with XFA data.- Parameters:
-
is
- theSAX input source
-
readOnly
- whether or not the resulting DOM document may be modified - Throws:
-
IOException
- if any I/O issue occurs on theInputSource
-
fillXfaForm
Replaces the XFA data under datasets/data.- Parameters:
-
node
- the inputNode
-
fillXfaForm
Replaces the XFA data under datasets/data.- Parameters:
-
node
- the inputNode
-
readOnly
- whether or not the resulting DOM document may be modified
-