Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Ajax call on acrobat form by javascript

Guest
Oct 06, 2016 Oct 06, 2016

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?

TOPICS
Acrobat SDK and JavaScript
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2016 Oct 06, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 06, 2016 Oct 06, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2016 Oct 06, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2016 Oct 06, 2016

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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 06, 2016 Oct 06, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2016 Oct 07, 2016

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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2016 Oct 07, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines