.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

PdfDocumentProcessor.CheckFormFieldNameCollisions(PdfAcroFormField[]) Method

Checks interactive form fields to find a collision in the form field names.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Docs.v21.1.dll

Declaration

public IList<PdfAcroFormFieldNameCollision> CheckFormFieldNameCollisions(
    params PdfAcroFormField[] fields
)

Parameters

Name Type Description
fields PdfAcroFormField[]

A PdfAcroFormField array of interactive form fields to check.

Returns

Type Description
IList<PdfAcroFormFieldNameCollision>

A collection of PdfAcroFormFieldNameCollision objects that contains information about a collision found in interactive form field names.

Remarks

When you create an intercative form field, make sure that its name is unique. Otherwise, a conflict might occur. The CheckFormFieldNameCollisions method allows you to check whether the form field’s name already exist in the document.

Use the CheckFormFieldNameCollisions method when you add a new form field to the loaded document.

The PdfAcroFormFieldNameCollision.Field property provides access to the conflicting form field.

Use the PdfAcroFormFieldNameCollision.ForbiddenNames property retrieve the collection of conflicting names.

The code sample below checks whether the created fields’ names already exist in the loaded document and renames the conflicting field.

List<PdfAcroFormField> fields = new List<PdfAcroFormField>();
fields.Add(textBox);
fields.Add(radioGroup);
//Check whether new form fields' names already exist in the document
IList<PdfAcroFormFieldNameCollision> collisions = processor.CheckFormFieldNameCollisions(fields);
if (collisions.Count == 0)
    Console.WriteLine("No name conflicts are detected");
else
{
    foreach (var collision in collisions)
    {
        //Rename conflicting field
        Console.WriteLine("The specified form field name ({0}) already exist in the document. Renaming...", collision.Field.Name);
        while (collision.ForbiddenNames.Contains(collision.Field.Name))
            collision.Field.Name = Guid.NewGuid().ToString();
    }
}
//Add fields to the document
//And save the result
processor.AddFormFields(fields);
processor.SaveDocument("Result.pdf");
See Also