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.

Wed May 18, 2016 5:20 pm

I am filling an editable pdf programmatically. But the pdf has those form fields where it puts one letter per box. There is a javascript being executed on focus and on blur that spaces the letters when you type it in manually. But when the field is filled through code, the javascript doesn't get triggered and the text doesn't get spaced out.

How can I trigger the on focus action event or the javascript programmatically?

example code
Code: Select all
        Private Shared Sub fill()
            Dim pdf As New Spire.Pdf.PdfDocument()
            pdf.LoadFromFile("file.pdf")

            Dim formWidget As PdfFormWidget = CType(pdf.Form, PdfFormWidget)
            Dim field As PdfField = CType(formWidget.FieldsWidget.List(0), PdfField)
            Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
            textBoxField.Text = "Las Vegas"

            pdf.SaveToFile("file.pdf")
            pdf.Close()
        End Sub


Attached file shows example of issue.
exampleIssue.png


Thanks in advance

msadovskiy
 
Posts: 7
Joined: Tue May 17, 2016 4:35 pm

Thu May 19, 2016 2:42 am

Hi,

Thanks for your posting.
Please try the following solution.
Code: Select all
  PdfDocument pdf = new PdfDocument();
                pdf.LoadFromFile("..\\..\\Abrechnung_SSL_02_Standard-prod-V3.pdf");
                PdfFormWidget form = pdf.Form as PdfFormWidget;
                if (form.XFAForm != null)
                {
                    List<XfaField> xfafields = form.XFAForm.XfaFields;
                   {
                      for (int i = 0; i < fields.Count; i++)
                     {
                       XfaField field = fields[i];
                       if (field is XfaTextField)
                      {
                        XfaTextField textBoxField = field as XfaTextField;
                       //......
                      }
                   }
                 }
                }


If the issue still exists, please share your pdf file for investigation.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Tue May 24, 2016 8:21 am

Hi,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Tue May 24, 2016 3:37 pm

Hi Amy,

Sorry for not replying.
I forgot to mention that I am using the Spire PDF free version 3.2. And it seems it doesn’t have any XFA features in that build. So instead, my solution was to edit the cells on the page open event through Javascript. It works for the most part.
Sorry, I am unable to share the PDF file because my client doesn’t want the form distributed.

Thanks for your help.

msadovskiy
 
Posts: 7
Joined: Tue May 17, 2016 4:35 pm

Wed May 25, 2016 1:39 am

Hi,

Thanks for your reply.
XFA feature is included in Spire.PDF Pack Version:3.7(trial version). We cannot replicate your issue and resolve it if we don't have your pdf document.

Please feel free to contact us if you have further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Thu May 26, 2016 11:59 pm

Hi
I am having the same problem, I have a script in the calc field, calculates a value and then changes the text box background color depending on the value

Mike

WesternIndustrial
 
Posts: 13
Joined: Wed Jul 08, 2015 4:11 am

Fri May 27, 2016 2:01 am

Hi Mike,

Thanks for your posting.
Is your scenario that first to get the value of textbox field and then to change the background color of textbox field depending on the value? Please share a sample pdf document so that we can work out a demo soon.

Thank you for further assistance.
Best Regards,
Amy
E-iceblue support team
User avatar

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

Fri May 27, 2016 3:36 pm

Thanks Amy

Trying to upload sample

WesternIndustrial
 
Posts: 13
Joined: Wed Jul 08, 2015 4:11 am

Mon May 30, 2016 3:08 am

Hi,

Thanks for your providing.
Here is sample code regarding setting back color of field according to field value.
Code: Select all
  PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(input);
            PdfFormWidget formWidget = pdf.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;
                    if (textboxField.Name == "Text1")
                    {
                        if (textboxField.Text == "1")
                        {
                            textboxField.BackColor = Color.DarkRed;
                        }
                    }
                }
            }
            string result = "7729.pdf";
            pdf.SaveToFile(result);


Please feel free to contact us if you need further assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Mon May 30, 2016 5:36 am

How do I get the Java script to run inside the pdf for the calculation?

Thanks

mike

WesternIndustrial
 
Posts: 13
Joined: Wed Jul 08, 2015 4:11 am

Mon May 30, 2016 9:07 am

Dear Mike,

Sorry that at present our Spire.PDF doesn't support the feature. But we have added it as new feature into our schedule. We will inform you when it is supported.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Tue May 31, 2016 8:18 pm

Thank you

Would there be some form of time line or expected launch date?

Mike

WesternIndustrial
 
Posts: 13
Joined: Wed Jul 08, 2015 4:11 am

Wed Jun 01, 2016 1:45 am

Dear Mike,

Our dev team is working on the issue and has got some progress, but we don't have a launch date of a new version now as we also need some time to do some tests when the case is finished. Anyway, we will inform you immediately when new version is ready.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Thu Jun 16, 2016 8:18 am

Dear Mike,

Thanks for your waiting.
The feature has been supported. Weclome to download and test Spire.PDF Pack(Hot Fix) Version:3.7.91.
Share sample code:
Code: Select all
 PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("..\\..\\New JSA 1.pdf");
            PdfFormWidget form = pdf.Form as PdfFormWidget;
            for (int i = 0; i < form.FieldsWidget.List.Count; i++)
            {
                PdfField field = form.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;
                    if (textbox.Name == "Text1")
                    {
                        PdfJavaScriptAction jsa = textbox.Actions.Calculate;
                        if (jsa != null)
                        {
                            //Get JavaScript
                            string js = jsa.Script;
                        }
                        //Give new JavaScript to textbox field
                        PdfJavaScriptAction action = new PdfJavaScriptAction(newJs);
                        textbox.Actions.Calculate = action;
                    }
                }
            }


Best Regards,
Amy
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron