Class XfaForm
java.lang.Object
com.itextpdf.forms.xfa.XfaForm
Processes XFA forms.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AcroFieldsSearchprivate Nodeprivate Xml2SomDatasetsprivate Documentprivate static final intprivate Nodestatic final StringThe 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 theDocumentcontaining all xml information -
Method Summary
Modifier and TypeMethodDescriptionprivate voidSome XFA forms don't have a datasets node.private voidExtracts the nodes from the domDocument.extractXFANodes(Document domDocument) Extracts DOM nodes from an XFA document.voidfillXfaForm(File file) Replaces the XFA data under datasets/data.voidfillXfaForm(File file, boolean readOnly) Replaces the XFA data under datasets/data.voidReplaces the XFA data under datasets/data.voidfillXfaForm(InputStream is, boolean readOnly) Replaces the XFA data under datasets/data.voidfillXfaForm(Node node) Replaces the XFA data under datasets/data.voidfillXfaForm(Node node, boolean readOnly) Replaces the XFA data under datasets/data.voidReplaces the XFA data under datasets/data.voidfillXfaForm(InputSource is, boolean readOnly) Replaces the XFA data under datasets/data.private NodefindDataNode(Node datasetsNode) findDatasetsName(String name) Finds the complete SOM name contained in the datasets section from a possibly partial name.findDatasetsNode(String name) Finds theNodecontained in the datasets section from a possibly partial name.findFieldName(String name) Finds the complete field name from a partial name.Gets theNodethat corresponds to the datasets part.Gets the top level DOM document.private NodegetFirstElementNode(Node src) static StringgetNodeText(Node n) Gets all the text contained in the child nodes of this node.private static StringgetNodeText(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 PdfObjectgetXfaObject(PdfAcroForm acroForm) Return the XFA Object, could be an array, could be a Stream.private static PdfObjectgetXfaObject(PdfDocument pdfDocument) Return the XFA Object, could be an array, could be a Stream.private voidinitXfaForm(PdfObject xfa) private voidinitXfaForm(InputStream inputStream) booleanReturnstrueif it is a XFA form.private static byte[]Serializes a XML document to a byte array.voidsetDomDocument(Document domDocument) Sets the top DOM document.voidsetNodeText(Node n, String text) Sets the text of this node.voidsetXfaFieldValue(String name, String value) Changes a field value in the XFA form.static voidsetXfaForm(XfaForm form, PdfAcroForm acroForm) Sets the XFA key from a byte array.static voidsetXfaForm(XfaForm form, PdfDocument pdfDocument) Sets the XFA key from a byte array.voidwrite(PdfAcroForm acroForm) Write the XfaForm to the providedPdfAcroForm.voidwrite(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
-
-
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
-
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 theXFAkey must contain correct XFA syntax. If theXFAkey 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- anPdfAcroForminstance- Throws:
IOException- if any I/O issue occurs
-
extractXFANodes
-
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
-
getXfaFieldValue
-
isXfaPresent
public boolean isXfaPresent()Returnstrueif it is a XFA form.- Returns:
trueif it is a XFA form
-
findFieldName
-
findDatasetsName
-
findDatasetsNode
-
getNodeText
-
getNodeTextByPath
-
setNodeText
-
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 theNodethat corresponds to the datasets part.- Returns:
- the
Nodethat corresponds to the datasets part
-
fillXfaForm
Replaces the XFA data under datasets/data. Accepts afile objectto 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 objectto fill this object with XFA data.- Parameters:
file- theFilereadOnly- 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 anInputStreamto 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 anInputStreamto fill this object with XFA data.- Parameters:
is- theInputStreamreadOnly- 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 sourceto 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 sourceto fill this object with XFA data.- Parameters:
is- theSAX input sourcereadOnly- whether or not the resulting DOM document may be modified- Throws:
IOException- if any I/O issue occurs on theInputSource
-
fillXfaForm
-
fillXfaForm
-
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:
IOExceptionSAXException
-
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
-