7 Replies Latest reply on Oct 7, 2016 9:34 AM by Test Screen Name

    Ajax call on acrobat form by javascript

    jebij17374415

      Is it possible to make an ajax call on acrobat form by javascript so that I can get data from server and fill the dropdown list item on runtime?

        • 1. Re: Ajax call on acrobat form by javascript
          try67 MVP & Adobe Community Professional

          No, you can't use Ajax in a PDF, but you can do an HTTP request or a call to a SOAP service. It's all documented under the Net object in the Acrobat JavaScript API Reference.

          • 2. Re: Ajax call on acrobat form by javascript
            jebij17374415 Level 1

            Thank you so much try67!

             

            I follow the Acrobat JavaScript API Reference to create the following script.js and put it into the folder level folder:

             

            function ajax(cURL) {

                var params =

                {

                        cVerb: "GET",

                        cURL: cURL,

                        oHandler:

                        {

                                response: function(msg, uri, e,h){

                                        var stream = msg;

                                        var string = "";

                                        string = SOAP.stringFromStream( stream );

                                        app.alert( string );

                                }

                        }

                };

             

                Net.HTTP.request(params);

            }

             

             

            then I create a button on the pdf form and call a javascript: ajax('http://localhost/app/ajaxCall');

            But it return this error: NotAllowedError: Security setting prevent access to this property or method.

             

            Any suggestions?

            • 3. Re: Ajax call on acrobat form by javascript
              try67 MVP & Adobe Community Professional

              Using this method requires "forms rights", which usually means a special right applied with a LiveCycle server application...

              • 4. Re: Ajax call on acrobat form by javascript
                Karl Heinz Kremer Adobe Community Professional

                When you look at the documentation, it says "This method can only be made outside the context of a document (for example, in a folder level JavaScript)."

                 

                You'll probably say "I am using it in a folder level script", but you are calling your function from within the document, so the function will run with the same privileges as if it would be defined within the document itself. Just having it defined in the folder level script does not change anything. You will need to create a trusted function for this to work in Acrobat. For Reader, you would still need to apply forms rights to the document (using the LiveCycle server).

                 

                See here for more information about trusted functions: Acrobat DC SDK Documentation - App.trustedFunction()

                • 5. Re: Ajax call on acrobat form by javascript
                  jebij17374415 Level 1

                  Thanks for response!

                   

                  What I want to do is use acrobat e-form to replace traditional web form in my web application, so I need to make a interactive e-form to deal with user selection.

                   

                  For example, one of the use case, I need to make an ajax call on acrobat form by javascript so that I can get data from server and fill the dropdown list item on runtime

                   

                  Is that acrobat e-from possible to act as traditional web form? Or LiveCycle server is the solution?

                   

                  Please advice!

                  • 6. Re: Ajax call on acrobat form by javascript
                    Karl Heinz Kremer Adobe Community Professional

                    You can submit form data via FDF or XFDF (or even HTML) and then respond back to the form with FDF or XFDF (in this case, HTML is not an option, that's why I stick with FDF/XFDF both ways). The only drawback is that you can only send and receive information in form fields, so you may need to create some hidden fields that you use just for this type of communication.

                     

                    Take a look at this for more information: Acrobat DC SDK Documentation - Doc.submitForm()

                    • 7. Re: Ajax call on acrobat form by javascript
                      Test Screen Name Most Valuable Participant

                      There is much to consider that you may not be aware of. Such a form would need the Mac or Windows version of Acrobat Reader. Can you force all your users to have this configuration? Are you sure nobody will ever want to use it from their tablet or phone? Frankly, I can see no reason whatever to move from working HTML forms to PDF forms. Even Adobe are moving away from it.