This is a migrated thread and some comments may be shown as answers.
Create new interactive forms field for each item in list
3 Answers 19 Views
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 11 Mar 2019, 11:23 AM

Good Morning, 

 

I'm currently working on a project which consists in using a foreach on a list which then I would like to create a new texbox for each of the items. 

Also please note that I'm new to this so sorry if I haven't explained it properly.  

When running the debugger it complains of the item having the same key when it comes around to create the second textbox. Which it would be referring to the the  "txtBox". 

 

Please see the snippet below: 

            foreach (var c in list)

            {
                  TextBoxField txtBox = new TextBoxField("txtBox");
                   
                    txtBox.IsRequired = true;
                    txtBox.IsReadOnly = true;
                    document.AcroForm.FormFields.Add(txtBox);
                    txtBox.Value = "abc";
                    editor.Position.Translate(0, 110);
                    editor.DrawWidget(txtBox, new System.Windows.Size (300, 100));
            };

 

 

Thanks

Marco

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 13 Mar 2019, 02:26 PM
Hello Marco,

Thank you for your interest in PdfProcessing.

When adding fields to a FormFieldCollection of an AcroForm, each field should have a unique name, as can be seen in the Form Fields section of the documentation. For example:
for (int i = 0; i < list.Count; i++)
{
    TextBoxField txtBox = new TextBoxField("txtBox" + i);
 
    txtBox.IsRequired = true;
    txtBox.IsReadOnly = true;
    document.AcroForm.FormFields.Add(txtBox);
    txtBox.Value = "abc";
    editor.Position.Translate(0, 110);
    editor.DrawWidget(txtBox, new System.Windows.Size(300, 100));
}

I hope this helps.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Marco
Top achievements
Rank 1
answered on 15 Mar 2019, 04:49 PM

Thanks that worked like a treat. Do I need to open another thread for a different question? it's still pdf processing. 

It's regarding dynamically creating a new pdf page. I won't always have the same amount of form fields. 

 

Best regards,

Marco

0
Georgi
Telerik team
answered on 20 Mar 2019, 01:48 PM
Hi Marco,

PDF is fixed document format and the elements in the page content are measured and positioned in a strict manner. In order to manipulate the position of a content element and find if the current position exceeds the page boundaries, you can use the Position property of the FixedContentEditor class. For example, before drawing a widget annotation, you can calculate the remaining page size and add a new page if the remaining size is insufficient to add a content element.

Please, find attached a sample project demonstrating this approach.

I hope this helps.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Marco
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Marco
Top achievements
Rank 1
Share this question
or