FieldLockInfo Class
Contains information about form fields that a signature locks.
Declaration
public class FieldLockInfo extends JavaObject
Remarks
Call one of the following methods to create a FieldLockInfo object:
| Method | Description |
|---|---|
| createAll() | Creates an object that locks all form fields in the document. |
| createInclude | Creates an object that locks the specified form fields. |
| createExclude | Creates an object that locks all form fields except the specified fields. |
Pass the object to the SignatureField.setLock(value) method before you save the signed document. In the signed document, PDF viewers do not allow users to modify locked fields. The PDF Document API does not save changes to locked fields in incremental updates.
Refer to the following help topic for additional information: Sign PDF Documents — PDF Document API for Java.
Example
Certify a PDF Document and Lock Form Fields
The following code snippet certifies a document, allows users to fill in forms and sign the document, and locks the Amount and Date form fields:
import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = Files.newInputStream(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream certificateStream = Files.newInputStream(Path.of("certificate.pfx"))) {
// Create a signature field and bind it to a widget on the first page.
SignatureField signatureField = new SignatureField("ManagerSignature");
pdfDocument.getFields().add(signatureField);
pdfDocument.getPages().getFirst().getAnnotations().add(
new SignatureWidgetAnnotation(signatureField, new RectangleF(20, 400, 200, 60)));
// Lock the "Amount" and "Date" fields after the field is signed.
signatureField.setLock(FieldLockInfo.createInclude(List.of("Amount", "Date")));
// Certify the document.
SignatureOptions options = new SignatureOptions();
options.setCertificate(certificateStream, "CERTIFICATE_PASSWORD");
options.setCertificationLevel(CertificationLevel.FILL_FORMS);
pdfDocument.addSignature(signatureField, options);
Files.createDirectories(Path.of("output"));
try (OutputStream outputStream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
pdfDocument.save(outputStream);
}
}
}
}
Inherited Members
Inheritance
Methods
createAll() Method
Creates an object that locks all form fields in the document.
Declaration
public static FieldLockInfo createAll()
Returns
| Type | Description |
|---|---|
FieldLockInfo |
An object that locks all form fields. |
createExclude(List<String> fieldNames) Method
Creates an object that locks all form fields except the specified fields.
Declaration
public static FieldLockInfo createExclude(List<String> fieldNames)
Parameters
| Name | Type | Description |
|---|---|---|
| fieldNames | java.util.List<java.lang.String> | Full names of form fields that remain editable. |
Returns
| Type | Description |
|---|---|
FieldLockInfo |
An object that locks all form fields except the specified fields. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Remarks
The API does not check whether the document contains the specified fields. Child fields of a listed field also remain editable.
createInclude(List<String> fieldNames) Method
Creates an object that locks the specified form fields.
Declaration
public static FieldLockInfo createInclude(List<String> fieldNames)
Parameters
| Name | Type | Description |
|---|---|---|
| fieldNames | java.util.List<java.lang.String> | Full names of form fields to lock. |
Returns
| Type | Description |
|---|---|
FieldLockInfo |
An object that locks the specified form fields. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Remarks
The API does not check whether the document contains the specified fields. The lock also applies to child fields of a listed field.
getAction() Method
Returns which form fields the signature locks.
Declaration
public FieldLockAction getAction()
Returns
| Type | Description |
|---|---|
| FieldLockAction | A value that specifies locked form fields. |
Remarks
The getAction() method returns one of the following values:
| Value | Description |
|---|---|
| ALL | The signature locks all form fields. |
| INCLUDE | The signature locks form fields that the FieldLockInfo.getFieldNames() method returns. |
| EXCLUDE | The signature locks all form fields except the fields that the FieldLockInfo.getFieldNames() method returns. |
Call the getFieldNames() method to get names of the listed fields.
getFieldNames() Method
Returns names of form fields that the lock includes or excludes.
Declaration
public List<String> getFieldNames()
Returns
| Type | Description |
|---|---|
| java.util.List<java.lang.String> | Full names of form fields; an empty list if the |
Remarks
If the getAction() method returns FieldLockAction.INCLUDE, the signature locks the listed fields. If the getAction() method returns FieldLockAction.EXCLUDE, the signature locks all fields except the listed fields.
The lock also applies to child fields of a listed field.