Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu May 05, 2016 8:13 am

Pension_Tfn_Declaration_form1.zip
Hi Team,

I was trying to autofile the attached PDF using spire through asp.net application, but i am getting a blank PDF created instead of autofill. below is the code for your reference, could you please let me know what would be the issues. We are planning to finish this tech Spike before going for purchase. I am suing spire.pdf dll and product version is 3.6.0.5020 :

private void LoadPDFform()
{
//Create a pdf document
PdfDocument doc = new PdfDocument();
//Load from file
doc.LoadFromFile(@"C:\Program Files (x86)\e-iceblue\Spire.Pdf\Demos\CS\Web\Pension_Tfn_Declaration_form1.pdf");

//Get form
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;


//Fill the data for textBoxField
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
switch (textBoxField.Name)
{

case "topmostSubform[0].Page1[0].txtLastName[0]":
textBoxField.Text = "Nagendra";
break;
case "TopmostSubform[0].Page1[0].nPostcode[0]":
// textBoxField.Password = true;
textBoxField.Text = "3146";
break;
case "topmostSubform[0].Page1[0].txtEmail[0]":
// textBoxField.Password = true;
textBoxField.Text = "[email protected]";
break;
}

}
}
//Save the document to file in PDF format
doc.SaveToFile(@"C:\Program Files (x86)\e-iceblue\Spire.Pdf\Demos\CS\Web\Pension_Tfn_Declaration_form1_filled.pdf");
//Launch the file
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\e-iceblue\Spire.Pdf\Demos\CS\Web\Pension_Tfn_Declaration_form1_filled.pdf");

}

[email protected]
 
Posts: 2
Joined: Sat Apr 30, 2016 9:55 pm

Thu May 05, 2016 9:45 am

Hello,

Thanks for your feedback and your file.
I have tested this file and noticed your issue. I have forwarded it to our dev team. We will inform you once it is resolved.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri May 06, 2016 3:15 am

Hello,

Please try the below solution:
Code: Select all
            //Create a pdf document
            PdfDocument doc = new PdfDocument();
            //Load from file
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Pension_Tfn_Declaration_form1.pdf");
            //Get form
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;
            if (formWidget.XFAForm != null)
            {
                List<XfaField> loFields = formWidget.XFAForm.XfaFields;
                for (int i = 0; i < loFields.Count; i++)
                {
                    // PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
                    //Fill the data for textBoxField
                    if (loFields[i] is XfaCheckButtonField)
                    {
                        (loFields[i] as XfaCheckButtonField).Checked = true;
                    }
                    if (loFields[i] is XfaTextField)
                    {
                        (loFields[i] as XfaTextField).Value = "Nagendra";
                    }
                }
            }
            //Save the document to file in PDF format
            doc.SaveToFile("Pension_Tfn_Declaration_form1_filled.pdf");
            //Launch the file
            System.Diagnostics.Process.Start("Pension_Tfn_Declaration_form1_filled.pdf");

If there is any question, welcome to get it back to us.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri May 06, 2016 6:37 am

Hi Caroline,

Thanks for the code, yes now its working fine. Just wanted to know when this did not work when i followed the steps that was provided in your website.

Regards,
Nagendra

[email protected]
 
Posts: 2
Joined: Sat Apr 30, 2016 9:55 pm

Fri May 06, 2016 7:27 am

Hello Nagendra,

Glad to hear that the code works for your scenario.
If there is any problem, welcome to feel free to get it back to us.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Return to Spire.PDF

cron