Package com.itextpdf.forms.xfa
Class XfaForm
java.lang.Object
com.itextpdf.forms.xfa.XfaForm
Processes XFA forms.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AcroFieldsSearch
private Node
private Xml2SomDatasets
private Document
private static final int
private Node
static final String
The URI for the XFA Data schema.private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionXfaForm()
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 TypeMethodDescriptionprivate void
Some XFA forms don't have a datasets node.private void
Extracts the nodes from the domDocument.extractXFANodes
(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.private Node
findDataNode
(Node datasetsNode) 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.private Node
getFirstElementNode
(Node src) static String
getNodeText
(Node n) Gets all the text contained in the child nodes of this node.private static String
getNodeText
(Node n, String name) getNodeTextByPath
(String path) Gets all the text contained in the child nodes of the node under the provided path.getXfaFieldValue
(String name) Gets the xfa field value.private static PdfObject
getXfaObject
(PdfAcroForm acroForm) Return the XFA Object, could be an array, could be a Stream.private static PdfObject
getXfaObject
(PdfDocument pdfDocument) Return the XFA Object, could be an array, could be a Stream.private void
initXfaForm
(PdfObject xfa) private void
initXfaForm
(InputStream inputStream) boolean
Returnstrue
if it is a XFA form.private static byte[]
Serializes a XML document to a byte array.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
-
INIT_SERIALIZER_BUFFER_SIZE
private static final int INIT_SERIALIZER_BUFFER_SIZE- See Also:
-
templateNode
-
datasetsSom
-
datasetsNode
-
acroFieldsSom
-
xfaPresent
private boolean xfaPresent -
domDocument
-
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 datapdfDocument
- 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 dataacroForm
- 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 changedvalue
- 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
-
getNodeTextByPath
Gets all the text contained in the child nodes of the node under the provided path.- Parameters:
path
- path to the node to extract text in the format "some.path.to.node"- Returns:
- text found under the provided path or
null
if node or text wasn't 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 totext
- 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
-
getNodeText
-
getXfaObject
Return the XFA Object, could be an array, could be a Stream. Returns null if no XFA Object is present.- Parameters:
pdfDocument
- a PdfDocument instance- Returns:
- the XFA object
-
getXfaObject
Return the XFA Object, could be an array, could be a Stream. Returns null if no XFA Object is present.- Parameters:
acroForm
- a PdfDocument instance- Returns:
- the XFA object
-
serializeDocument
Serializes a XML document to a byte array.- Parameters:
n
- the XML document- Returns:
- the serialized XML document
- Throws:
IOException
- if any I/O issue occurs
-
initXfaForm
private void initXfaForm(PdfObject xfa) throws IOException, ParserConfigurationException, SAXException -
initXfaForm
- Throws:
IOException
SAXException
-
extractNodes
private void extractNodes()Extracts the nodes from the domDocument. -
createDatasetsNode
Some XFA forms don't have a datasets node. If this is the case, we have to add one. -
getFirstElementNode
-
findDataNode
-