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.

Sat Dec 05, 2015 12:37 am

Hi
I am filling a pdf file with SSN field, with our spire.PDF the letters are not properly filled in the raster. Please see the "not good.png", but when I manually filled the field it looks good, please see the "good.png". So I want to check if there is a way to fill the field properly?

Thanks.
Leon

[email protected]
 
Posts: 2
Joined: Fri Dec 04, 2015 3:28 am

Mon Dec 07, 2015 2:35 am

Hi,

Thanks for your inquiry.
To help us do an investigation, please share your pdf document and code.
Thank you.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Fri Dec 11, 2015 5:21 pm

Hi Amy,

Thank you for your reply.

the document is W-9 Form which please find enclosed. the following are the code to fill the SSN fields:


PdfDocument doc = new PdfDocument();
doc.LoadFromFile(formFile);
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
switch (textBoxField.Name)
{

case "topmostSubform[0].Page1[0].SSN[0].f1_11[0]":
if (socialSecurityNumber.Length > 2)
textBoxField.Text =socialSecurityNumber.Substring(0, 3);
break;
case "topmostSubform[0].Page1[0].SSN[0].f1_12[0]":
if (socialSecurityNumber.Length > 5)
textBoxField.Text = socialSecurityNumber.Substring(3, 2);
break;
case "topmostSubform[0].Page1[0].SSN[0].f1_13[0]":
if (socialSecurityNumber.Length > 8)
textBoxField.Text = socialSecurityNumber.Substring(5, 4);
break;
}
}

}

doc.SaveToFile( "-fw9.pdf");

[email protected]
 
Posts: 2
Joined: Fri Dec 04, 2015 3:28 am

Mon Dec 14, 2015 3:38 am

Hi,

Thanks for providing.
Please try the following solution:
Code: Select all
 PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;
            List<XfaField> fields = formWidget.XFAForm.XfaFields;
            for (int i = 0; i < fields.Count; i++)
            {
                XfaField field = fields[i];
                if (field is XfaTextField)
                {
                    XfaTextField textBoxField = field as XfaTextField;
                    switch (textBoxField.Name)
                    {

                        case "topmostSubform[0].Page1[0].SSN[0].f1_11[0]":

                            textBoxField.Value = socialSecurityNumber.Substring(0, 3);
                            break;
                        case "topmostSubform[0].Page1[0].SSN[0].f1_12[0]":

                            textBoxField.Value = socialSecurityNumber.Substring(3, 2);
                            break;
                        case "topmostSubform[0].Page1[0].SSN[0].f1_13[0]":

                            textBoxField.Value = socialSecurityNumber.Substring(5, 4);
                            break;
                    }
                }

            }
            doc.SaveToFile(output);


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF