IDocumentFormFieldCollection Interface
A collection of form fields in a PDF document that also contains document-level form settings.
Declaration
public interface IDocumentFormFieldCollection extends IFormFieldCollection
Remarks
Call the PdfDocument.getFields() method to access form fields of a PDF document. The IDocumentFormFieldCollection interface extends IFormFieldCollection with settings that apply to the document’s interactive form.
IDocumentFormFieldCollection members allow you to do the following:
- Ask PDF viewers to generate form field appearances (setNeedAppearances(boolean value)).
- Get and specify signature flags (getSignatureFlags() and setSignatureFlags(FormSignatureFlags value)).
- Check whether the document contains XFA form data and remove the data (getHasXfa() and removeXfa()).
Note
The API saves values passed to setNeedAppearances(value) and setSignatureFlags(value) methods only if the document contains form fields.
Refer to the following help topic for additional information: Work with PDF Forms (AcroForms).
Example: Remove XFA Data and Check Signature Flags of a PDF Form
The following code snippet removes XFA form data from a document, asks PDF viewers to generate form field appearances, and checks whether the form contains signatures:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
public class Main {
public static void main(String[] args) throws Exception {
Files.createDirectories(Path.of("output"));
try (InputStream inputStream = Files.newInputStream(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
IDocumentFormFieldCollection fields = pdfDocument.getFields();
// Remove XFA form data to keep AcroForm fields only.
if (fields.getHasXfa())
fields.removeXfa();
// Ask PDF viewers to generate appearances for form fields.
fields.setNeedAppearances(true);
// Check whether the form contains signatures.
FormSignatureFlags flags = fields.getSignatureFlags();
System.out.println("Signature flags: " + flags);
System.out.println("Contains signatures: " + flags.hasFlag(FormSignatureFlags.SIGNATURES_EXIST));
System.out.println("Save incrementally: " + flags.hasFlag(FormSignatureFlags.APPEND_ONLY));
try (OutputStream outputStream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
pdfDocument.save(outputStream);
}
}
}
}
Implements
Methods
getHasXfa() Method
Returns whether the document contains XFA form data.
Declaration
public abstract boolean getHasXfa()
Returns
| Type | Description |
|---|---|
| boolean |
|
getNeedAppearances() Method
Returns whether the interactive form asks PDF viewers to generate appearances for form fields.
Declaration
public abstract boolean getNeedAppearances()
Returns
| Type | Description |
|---|---|
| boolean |
|
getSignatureFlags() Method
Returns signature flags for the document’s interactive form.
Declaration
public abstract FormSignatureFlags getSignatureFlags()
Returns
| Type | Description |
|---|---|
| FormSignatureFlags | Signature flags. |
removeXfa() Method
Removes XFA form data from the document.
Declaration
public abstract void removeXfa()
Remarks
XFA (XML Forms Architecture) forms store form layout and data in XML. A hybrid PDF document contains both XFA data and AcroForm fields. The PDF Document API works with AcroForm fields. If you modify AcroForm fields in a hybrid document, remove XFA data so that PDF viewers that support XFA display the AcroForm fields.
The API removes XFA data when you save the document. After you call the removeXfa method, the getHasXfa() method returns false.
setNeedAppearances(boolean value) Method
Sets whether the interactive form asks PDF viewers to generate appearances for form fields.
Declaration
public abstract void setNeedAppearances(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
Remarks
If you call the setNeedAppearances(true) method, the interactive form asks a PDF viewer to construct appearance streams for all widget annotations when the viewer opens the document.
setSignatureFlags(FormSignatureFlags value) Method
Sets signature flags for the document’s interactive form.
Declaration
public abstract void setSignatureFlags(FormSignatureFlags value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FormSignatureFlags | Signature flags. |
Remarks
Signature flags tell PDF applications whether the document contains signature fields and whether to save changes as an incremental update to keep existing signatures valid. When the API signs a document, it sets SIGNATURES_EXIST and APPEND_ONLY flags.
To combine flags, pass the combined integer value to the FormSignatureFlags.fromValue(value) method (for example, FormSignatureFlags.fromValue(FormSignatureFlags._SIGNATURES_EXIST | FormSignatureFlags._APPEND_ONLY)).
The API saves signature flags only if the document contains form fields.
The setSignatureFlags method accepts the following values:
| Value | Description |
|---|---|
| NONE | The interactive form does not specify signature flags. |
| SIGNATURES_EXIST | The document contains at least one signature field. |
| APPEND_ONLY | The document contains signatures. Save changes as an incremental update to keep the signatures valid. |