13 Replies Latest reply on Apr 1, 2009 12:38 PM by (Cheryl_Gonzalez)

    PDF FORM RATHER SLOW and SLUGGISH

      Hey all.

      I am making a PDF form in Acrobat 9 with something like 100 fields. I am running basic javascript validation routines on it. The end result is a rather sluggish PDF. My PC has an AMD Athlon in it. More then good enough I would think for a simple form. However, when clicking on the radio buttons, which is where I placed a bunch of validation and conditions to calculate values and hide/make visible some fields, make other fields required. Stuff like that, the transitions between the old view and the new view, takes up to 4 or 5 seconds. This seems like an incredibly long time. Does anyone haev any advice?

      Thanks!

      Bret
        • 1. Re: PDF FORM RATHER SLOW and SLUGGISH
          George_Johnson MVP & Adobe Community Professional
          It's hard to tell what's up without looking at the form, but you do have to be careful with calculated fields. The calculate event for each calculated field is triggered whenever ANY other form field value changes (not just those upon which it depends), in the order defined by the field calculation order.

          I usually try to keep calculation scripts to a minimum. One way to do this is to perform the calculation not in the calculate event, but in the validation (or mouse up, etc.) of the fields upon which its value depends.

          For example, suppose you have a text field whose value depends on the value of three other text fields. In the Validate event of each of the three input text fields, you could call a routine which gets the relevant field values, performs the calculation, and assigns the result to the value of the calculated field.

          You can also create a single routine which performs the calculations for all calculated fields in one pass. Also, be aware that you can control the automatic calculation of fields via JavaScript using app.calculate and doc.calculate properties and the doc.calculateNow() method.

          George
          • 2. Re: PDF FORM RATHER SLOW and SLUGGISH
            gkaiseril MVP & Adobe Community Professional
            You can also look at using the callable function, especially placing can creating document level functions. If you read the JavaScript API reference, one learns that Acrobat JS is tokenized and then run. Document level functions are tokenized once so there can be a performance improvement. Also keeping things within a functions cuts down on reallocating variables each time an action script is run that defines a variable.
            • 3. Re: PDF FORM RATHER SLOW and SLUGGISH
              Level 1
              I have included a copy of the script I am running. I have changed field names to protect the innocent and such. :)

              So this is a pretty simple script. I simply click on the radio button that this script is attached to on a "Mouse Down" event to run a Javascript and it seriously takes 4 seconds for the fields to show.

              // rbtn_field1 field1 button javascript
              // labels
              var lbl_field_1 = this.getField("lbl_field_1");
              var lbl_field_2 = this.getField("lbl_field_2");
              var lbl_field_3 = this.getField("lbl_field_3");
              var lbl_field_4 = this.getField("lbl_field_4");
              var lbl_field_5 = this.getField("lbl_field_5");
              var lbl_field_6 = this.getField("lbl_field_6");
              var lbl_field_7 = this.getField("lbl_field_7");
              var lbl_field_8 = this.getField("lbl_field_8");
              var lbl_field_9 = this.getField("lbl_field_9");
              var lbl_field_10 = this.getField("lbl_field_10");
              var lbl_field_11 = this.getField("lbl_field_11");
              var lbl_field_12 = this.getField("lbl_field_12");
              var lbl_field_13 = this.getField("lbl_field_13");
              var lbl_field_14 = this.getField("lbl_field_14");

              // text boxes
              var tbox_field1 = this.getField("tbox_field1");
              var tbox_field2 = this.getField("tbox_field2");
              var tbox_field3 = this.getField("tbox_field3");
              var tbox_field4 = this.getField("tbox_field4");
              var tbox_field5 = this.getField("tbox_field5");
              var tbox_field6 = this.getField("tbox_field6");
              var tbox_field7 = this.getField("tbox_field7");
              var tbox_field8 = this.getField("tbox_field8");
              var tbox_field9 = this.getField("tbox_field9");
              var tbox_field10 = this.getField("tbox_field10");

              // radio buttons

              var rbtn_field1 = this.getField("rbtn_field1");

              // set them hidden - labels
              lbl_field1.display = display.hidden;
              lbl_field2.display = display.hidden;
              lbl_field3.display = display.hidden;
              lbl_field4.display = display.hidden;
              lbl_field5.display = display.hidden;
              lbl_field6.display = display.hidden;
              lbl_field7.display = display.hidden;
              lbl_field8.display = display.hidden;
              lbl_field9.display = display.hidden;
              lbl_field10.display = display.hidden;
              lbl_field11.display = display.hidden;
              lbl_field12.display = display.hidden;
              lbl_field13.display = display.hidden;
              lbl_field14.display = display.hidden;

              // set them hidden - text boxes
              tbox_field1.display = display.hidden;
              tbox_field2.display = display.hidden;
              tbox_field3.display = display.hidden;
              tbox_field4.display = display.hidden;
              tbox_field5.display = display.hidden;
              tbox_field6.display = display.hidden;
              tbox_field7.display = display.hidden;
              tbox_field8.display = display.hidden;
              tbox_field9.display = display.hidden;
              tbox_field10.display = display.hidden;

              // set them hidden - radio buttons
              rbtn_field1.display = display.hidden;

              // set them to not required
              tbox_field1.required = false;
              tbox_field2.required = false;
              tbox_field3.required = false;
              tbox_field4.required = false;
              tbox_field5.required = false;
              tbox_field6.required = false;
              tbox_field7.required = false;
              tbox_field8.required = false;
              tbox_field9.required = false;
              tbox_field10.required = false;
              rbtn_field11.required = false;
              • 4. Re: PDF FORM RATHER SLOW and SLUGGISH
                MarkWalsh Level 4
                One thing I would suggest is that you change your naming conventions to use dots instead of underscores for your repetitions.

                Instead of

                "lbl_field_9"

                you can say

                "lbl_field.9"

                That way, you could address all fields with one command

                this.getField("lbl_field").hidden = display.hidden

                This would hide all of the fields that were named "lbl_field.X" no matter how many you added.
                • 5. Re: PDF FORM RATHER SLOW and SLUGGISH
                  gkaiseril MVP & Adobe Community Professional
                  I would use the 'mouse up' action to allow for cancellation by dragging off the radio button. I would also cut down on the variable definitions and use control loops for repetitive processes and if I have an object process all the properties and methods for that object so the JS engine does not need to acquire focus on that item.

                  So one can have a document level function like:

                  function FNrbtn_Field1() {
                  // set them hidden - labels
                  for(i = 1; i < 15, i++) {
                  this.getField("lbl_field_" + 1).display = display.hidden;
                  }

                  // set them hidden and not required- text boxes
                  for( i = 1; i < 11; i++) {
                  this.getField("tbox_field" + i).display = display.hidden;
                  this.getField("tbox_field" + i).required = false;
                  }

                  // set them hidden and not required - radio buttons
                  this.getField("rbtn_field1").display = display.hidden;
                  this.getField("rbtn_field1").required = false;

                  return;
                  } // end FNrbtn_Field1

                  Add a 'mouse up' action for the "rbtn_field1" JavaScript of:

                  // process the fields for this button:
                  FNrbtn_Field1();

                  If you were to rename you fields to "fieldName.#" starting at zero, there are other statements that could be used to automatic ally determine the number of fields with the level name of "fieldName" and that value could be used within the control loops so if more fields are added the scripts will automatically update, or address the common field properties with just the high level name.
                  • 6. Re: PDF FORM RATHER SLOW and SLUGGISH
                    George_Johnson MVP & Adobe Community Professional
                    You should consider using a hierarchical naming for your fields. For example, if you were to use field names like:

                    lbl_field.1, lbl_field.2, ...lbl_field.14,

                    You can set a particular property for the group of fields with a single statement:

                    getField("lbl_field").display = display.hidden;

                    getField(rbtn_field").required = false;

                    Also, when you're changing the visible appearance of a lot of fields, you should always consider turning off the redrawing of the fields while you're applying the changes, and cause Acrobat to redraw after everything is done. You do this using the "delay" document property:

                    // Prevent redrawing
                    delay = true;

                    // Make field changes here

                    // Force a redraw
                    delay = false;


                    If you don't want to change your field names, there's other things you can do. For example, it doesn't appear there's a need to use all of those variables. You can instead do:

                    getField("lbl_field_3").display = display.hidden;

                    Also, though it probably wouldn't save much on execution speed, you can use a loop to simplify the code:


                    // Get the display.hidden value
                    var DH = display.hidden;
                    for (var i = 1; i < 15; i++) {

                        getField("lbl_field" + i).display = DH;

                    }

                    I'd be interested to know if any of these suggestions make a difference.

                    George
                    • 7. Re: PDF FORM RATHER SLOW and SLUGGISH
                      Level 1
                      Wow guys. Thanks. I will try to implement these suggestions. It will take me a couple days though as I have about 400 fields (per Acrobat) across two pages of this form. I will begin function calls an rename all my fields. I will definitely try that "delay" command as well. That can be done inside of a function as well right?

                      Geo is the JS engine pretty efficient? How does it handle these requests? Is it like a system runtime or does the Acrobat application itself have the JS interpreter?

                      Thanks again all!

                      I'll post back when I have results! :)
                      • 8. Re: PDF FORM RATHER SLOW and SLUGGISH
                        gkaiseril MVP & Adobe Community Professional
                        Yes, the delay for the doc and field can be used within any function call.

                        Acrobat uses the Sun JavaScript engine and does everything as the scripts are called. Folder application scripts are checked and tokenized when Acrobat/Reader opens and the results are kept in memory so they run pretty quick, document level scripts are tokenized when the PDF is opened and retained in memory, field and page scripts are rerun each time they are triggered. PDF's are a mixed bag. Most post are address a specific problem and most requesters do not know a lot of advanced programing, so functions, control loops, arrays, and object manipulation are do not come up very often.
                        • 9. Re: PDF FORM RATHER SLOW and SLUGGISH
                          George_Johnson MVP & Adobe Community Professional
                          Setting the delay appropriately will probably have the biggest impact by far. Since it involves just two additional lines of code, you should be able to tell fairly quickly just how much.

                          George
                          • 10. Re: PDF FORM RATHER SLOW and SLUGGISH
                            Level 1
                            Hey guys, this sped things up quite a bit. Are there any ways I can go further by loading things at the document open, decreasing the number of redraws, etc?

                            Thanks!

                            Bret
                            • 11. Re: PDF FORM RATHER SLOW and SLUGGISH
                              gkaiseril MVP & Adobe Community Professional
                              Use docuemnt level functions for repetative actions, for extending and summing tables use the total field for the calculation calling a document level function. Limit the use of variable outside of funcitons or declaring them at the document level.
                              • 12. Re: PDF FORM RATHER SLOW and SLUGGISH
                                Hallo!

                                Do you have print commands to the console
                                (console.println("something"))
                                in your forms/javascripts?
                                they might be responsible for timing-problems...

                                Dieter
                                • 13. Re: PDF FORM RATHER SLOW and SLUGGISH
                                  I recently loaded Acrobat 9 Pro and have the same issue with tabbing in forms being slow.
                                  We did not build this form, we downloaded it from a major vendor.
                                  Is there anything we can do on our end to speed this up?

                                  Thanks,

                                  C