Skip to main content

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
FormFieldNameCollision

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.