FormFieldNameCollision Class
Contains information about form fields that have the same full name.
Declaration
public class FormFieldNameCollision extends JavaObject
Remarks
Use AppendDocumentResult.getResolvedFieldNameConflicts() method to access form field name conflicts that the API resolved during the append/merge operation.
The following code snippet finds form fields with the same name, merges each group into a single target field, and saves the updated PDF document:
package pdf;
import com.devexpress.docs.pdf.*;
import java.nio.channels.*;
import java.nio.file.*;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
try (FileChannel channel = FileChannel.open(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(channel)) {
// Get form field name collisions.
for (FormFieldNameCollision collision : pdfDocument.getFieldNameCollisions()) {
System.out.println("Field name: " + collision.getFullName());
List<FormField> fields = collision.getFields();
if (fields.size() > 1) {
// Merge fields with the same name.
FormField target = fields.getFirst();
FormField[] sources = fields.subList(1, fields.size())
.toArray(new FormField[0]);
pdfDocument.mergeFormFields(target, sources);
}
}
try (WritableByteChannel writableByteChannel =
FileChannel.open(Path.of("Document_Updated.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(writableByteChannel);
}
}
}
}
Refer to the following help topic for additional information: Merge PDF Documents.
Inherited Members
Inheritance
FormFieldNameCollision(String fullName, List<FormField> fields)
Initializes a new instance of the FormFieldNameCollision class with the specified full name and form fields.
Declaration
public FormFieldNameCollision(String fullName, List<FormField> fields)
Parameters
| Name | Type | Description |
|---|---|---|
| fullName | String | The full name shared by form fields. |
| fields | java.util.List<FormField> | A list of form fields that have the same full name. |
Methods
getFields() Method
Returns form fields that have the same full name.
Declaration
public List<FormField> getFields()
Returns
| Type | Description |
|---|---|
| java.util.List<FormField> | A list of form fields that have the same full name. |
getFullName() Method
Returns the full name of colliding form fields.
Declaration
public String getFullName()
Returns
| Type | Description |
|---|---|
| String | The full name of colliding form fields. |