4 Replies Latest reply on May 13, 2012 10:10 AM by saratogacoach

    Scripting for PDF

    saratogacoach Level 1

      Hi,

       

      I am trying to create a basic JS script for an Acrobat X Pro created PDF, to have it on opening check the launching URL, and if not a specific, hard-coded URL in the script, to navigate to a URL redirect page (or alternatively, to close the PDF).

       

      So, far, haven't been able to get it to work. I think that I am following the guidelines, but I must be doing something wrong. 

       

      I used the JS editor to add a simple, document level script:

       

      if (doc.Url != "xyz.com")

      {

      doc.closeDoc();

      }

       

      //OR, the one I used in the test PDF (see link below)

       

      if (doc.Url != "xyz.com")

      {

      this.getURL(www.xyz/redirect.html);

      }

       

      Saved and re-opened the PDF, and nothing happens...

       

      My test PDF with scripting in the JavaScript editor is at:

       

      www.elearningprojects.com/abc.pdf

       

      Can't get this to work, so far.

       

      Any help appreciated.

       

      Regards,

        • 1. Re: Scripting for PDF
          gkaiseril MVP & Adobe Community Professional

          Have you looked at the JavaScript debugging console in Acrobat for errors?

          1 person found this helpful
          • 2. Re: Scripting for PDF
            saratogacoach Level 1

            Hi,

             

            I'm new to scripting in Acrobat. Thank you for suggesting the debugger.

             

            It appears that getURL is not permitted by the security feature. I tried app.launchURL which works, but even if I follow it with closeDoc, the PDF stays open after the redirect.

             

            The only script that works is closeDoc. I'm using a condition if...to check if the URL != to a scripted URL. Even if the URL is correct (checks out), if I add an app.alert before closeDoc ("unauthorized to view the PDF"), the alert still displays (when it shouldn't).

             

            So far, a bit of a mess.

             

            It seems that a single script action in a conditional (for example, closeDoc), executes OK, but add a second action within the same conditional and it doesn't work as it should.

             

            I have been removing the function {} part, just adding the plain script: if... and  1 or 2 actions. I'm not sure how to set up an initial/opening event to trigger a function.

             

            I wonder if removing this function aspect causes second actions to fail to work properly?

             

            Any suggestions appreciated.

             

            Regards,

            • 3. Re: Scripting for PDF
              Dave Merchant MVP & Adobe Community Professional

              You really should read the documentation about Acrobat scripting, as your code is wrong in a lot of ways.

               

              • JS is case sensitive - the property is "URL" not "Url".
              • You can't refer to "doc" from within a document - it's "this" or nothing: "this.URL" or just "URL".
              • You can't check for an inequality (!=) as the URL property contains much more than the domain name - you have to search for substrings.
              • You can't close a PDF from within a Web browser.
              1 person found this helpful
              • 4. Re: Scripting for PDF
                saratogacoach Level 1

                Hi David,

                 

                Thank you for this explanation. I have downloaded and been reading the Acrobat JavaScript SDK. Have been trying to read and understand the syntax. One of the difficulties is not knowing which terms to look up, since I'm not familiar with the labels used to designate actions, triggering events. Been piecing it together. Wish there were more script examples: a respository for those with correct syntax.

                 

                I've tried:

                 

                var mURL = this.URL.substring(0,26);

                 

                if (mURL = http://www.xyz.com/abc.pdf)

                {

                app.alert("success");

                 

                else

                {

                this.closeDoc();

                }

                 

                Does not work.

                 

                Again, thanks for your help and explanations.

                 

                Regards,