Wildcard Form Fields

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  Re: Wildcard Form Fields

DynamicPDF CoreSuite for .NET (v9) Forum

 Mar 05 2018 10:44 AM
Have a need to assemble hundreds of combinations of PDF forms together, Most of which have the same form field names.  Trying to avoid individually naming every field in every document for duplicate entry needs.

When using MergeDocument.Merge(doc1, doc2);     Lets say doc1 and doc2 both have a ClientName field, the merger renames the field in doc2 to ClientName(2) to avoid the conflict.

Seeking a way to get assembledpolicy.Form.Fields["ClientName"].Value = clientname;     to set the value on all fields that start with ClientName  - I have tried using regex and get return that it is unable to recognize it.

Any ideas?

 Mar 05 2018 4:13 PM
Posted by a ceTe Software moderator
Hello,

Our API doesn’t allow for duplicate form field names, when you merge PDF forms with same names, the field names are automatically renamed. It is not possible to specify a wild card to set the form field values. However, you control the renaming with the help of MergeOption.RootFormField property and set the field values using the new names.

            PdfDocument pdf = new PdfDocument(@"TestForm.pdf");
            MergeDocument finalDocument = new MergeDocument();

            //merging the same form 10 times.
            for (int i = 0; i < 10; i++)
            {
                MergeOptions options = new MergeOptions();
                //Form fields are renamed as 1.fieldname in the first form, 2.fieldname in the second form and so on.
                options.RootFormField = i.ToString();
                finalDocument.Append(pdf, options);

                //set the desired form field value. 
                string fldName = i.ToString() + "." + "Name";
                finalDocument.Form.Fields[fldName].Value = "Name" + i.ToString();
            }

            finalDocument.Draw(@"MergedOutput.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 3:36 PM.