18 Replies Latest reply on Aug 24, 2011 9:58 AM by tygr

    Launch PDF from HTML and execute search

    tygr

      Is it possible using JavaScript in an HTML doc to launch a PDF and execute a search.query with a passed-in search parameter? TIA

        • 1. Re: Launch PDF from HTML and execute search
          tygr Level 1

          Follow-up:  If the answer is NO (which I expect) I guess I could create an empty "search" PDF and have it execute the search script when it is loaded.  I would need a seperate "search" PDF for each term.  Any suggestions for a better way?  I am very new to PDF scripting.

          • 3. Re: Launch PDF from HTML and execute search
            George_Johnson MVP & Adobe Community Professional

            The forum software had a problem with that URL, but you should get the idea.

            • 4. Re: Launch PDF from HTML and execute search
              tygr Level 1

              Thanks for the quick response!!  I'll give it a try.

               

              Jon Camp

              Senior Computer Scientist

               

              Applied Research Associates, Inc.

              North Florida Division

              Training Solutions Group

              430 W 5th Street Suite 700

              Panama City, FL  32401

              comm: 850-914-3188 x203

              fax: 850-914-3189

              email: jcamp@ara.com

              • 5. Re: Launch PDF from HTML and execute search
                tygr Level 1

                Thanks again, but that is not going to get me what I want.  I need to execute a query like:

                 

                // Split the file path into an array
                var aPath = this.path.split("/");
                // Remove the last element, which is the file name
                aPath.pop();
                // Join the path elements back together and add the index file
                var cIdxPath = aPath.join("/") + "/some.pdx";
                search.query ("some search term", "Index", cIdxPath);

                 

                I suppose I can have a script like this execute automatically when a PDF file is opened??  TIA

                • 6. Re: Launch PDF from HTML and execute search
                  tygr Level 1

                  Ok, the script works when I launch the PDF directly into the reader, but not when I launch from a browser.  I tried turning off browser launch in the preferences and the PDF will launch in the reader instead, but it still won't execute the script?  Anybody have a solution?  Thanks.

                  • 7. Re: Launch PDF from HTML and execute search
                    George_Johnson MVP & Adobe Community Professional

                    Where did you place the script, exactly? And can you give an example of the URL?

                    • 8. Re: Launch PDF from HTML and execute search
                      tygr Level 1

                      Hello, George, thanks for following up.  I went into Advanced->Document Processing->Document JavaScripts and put the code at the top of the file outside of the dummy function declaration I had to insert to activate the edit button.  It looks like this:

                       

                      // Split the file path into an array

                      var aPath = this.path.split("/");

                      // Remove the last element, which is the file name

                      aPath.pop();

                      // Join the path elements back together and add the index file

                      var cIdxPath = aPath.join("/") + "/Support Documents/SupDocs.pdx";

                      search.query ("Enhanced Tactical Automated Security System (eTASS)", "Index", cIdxPath);

                       

                      function Search()

                      {

                      }

                       

                       

                      It runs fine when I launch the PDF directly into the reader by double-clicking in file explorer in the folder above "Support Documents".  When I load the PDF from an HTML file in the same folder, however, the script does not run.  I set the reader preferences to force loading in the reader even when launched from a browser, and the script still will not execute.  I tried adding a button to the PDF and attaching the search script to it.  Again, it runs when launching directly but not from the HTML document.  Otherwise, the PDF is empty, and I'm using a relative URL and JS to load it from the HTML doc, such as:

                       

                      document.location = "mySearch.PDF"

                       

                      or

                       

                      window.open("mySearch.PDF", "searchwin");

                       

                      Neither one works.  This product has to run from a CD-ROM, so I haven't bothered to test it via http service.  Any suggestions?  Thanks again!

                       

                      Jon Camp

                      Senior Computer Scientist

                       

                      Applied Research Associates, Inc.

                      North Florida Division

                      Training Solutions Group

                      430 W 5th Street Suite 700

                      Panama City, FL  32401

                      comm: 850-914-3188 x203

                      fax: 850-914-3189

                      email: jcamp@ara.com

                      • 9. Re: Launch PDF from HTML and execute search
                        George_Johnson MVP & Adobe Community Professional

                        It probably has to do with the difference in the path when opened in Acrobat and when opened in the browser. For example, when I open a document in Acrobat, the path will look like this:

                         

                        /C/Documents and Settings/George Johnson/My Documents/docPath.pdf
                        

                         

                        But when the same file is opened in Firefox, the path is:

                         

                        file:///C|/Documents%20and%20Settings/George%20Johnson/My%20Documents/docPath.pdf
                        

                         

                        So you will have to modify your script to take this difference into account. Also, check the JavaScript console (Ctrl+J) for any errors.

                         

                        Regarding the dummy function, it's OK to delete that.

                        • 10. Re: Launch PDF from HTML and execute search
                          George_Johnson MVP & Adobe Community Professional

                          Jon,

                           

                          When you replay by email it includes personal information that you may not want posted on these public forums. You may want to return to the forum and report your posts and request that this information be removed. A forum moderator should then remove it.

                          • 11. Re: Launch PDF from HTML and execute search
                            tygr Level 1

                            Thanks, George, but that isn't it, either.  If I use this.path in the script I get the first type of path for both the direct launch and launching through browser (into reader).  If I use this.URL in the script I get the second type of path.  Neither works, but thanks for the heads-up on the JS console as it shows a security error:

                             

                            NotAllowedError: Security settings prevent access to this property or method.

                            Search.query:7:Document-Level:Search

                             

                            Is there a way to configure this?  I read somewhere else today that search.query is not available in a PDF that is launched from a browser.  I appreciate your assistance.  I might just deep-six this feature and be done with the project.  The client can always directly launch the PDF to get to the search.  Jon

                            • 12. Re: Launch PDF from HTML and execute search
                              George_Johnson MVP & Adobe Community Professional

                              You can use the decodeURI string method to help convert the path that gets returned when viewed in a browser. For example:

                               

                              var path1 = "file:///C|/Documents%20and%20Settings/George%20Johnson/My%20Documents/docPath.pdf";
                              var path2 = decodeURI(s).replace(/^file\:\/\/\/(\w)\|/, "/$1");
                              


                              path2 will be:

                               

                              /C/Documents and Settings/George Johnson/My Documents/docPath.pdf
                              
                              • 13. Re: Launch PDF from HTML and execute search
                                George_Johnson MVP & Adobe Community Professional

                                I hadn't considered that before, but the query method does have security restrictions that will probably preclude its use in this case. Sorry.

                                • 14. Re: Launch PDF from HTML and execute search
                                  tygr Level 1

                                  Ok, so I created a folder level script file to create a trusted function and it exhibits the same behavior - runs fine when launching directly into Acrobat but gives a security error when I launch the PDF from a browser, even when I force the doc to load in reader.  Is it the case that the search.query function simply cannot run from a browser when the index parameter is used?

                                  • 15. Re: Launch PDF from HTML and execute search
                                    George_Johnson MVP & Adobe Community Professional

                                    Did you also add the folder-level JavaScript to the Reader installation as well?

                                    • 16. Re: Launch PDF from HTML and execute search
                                      tygr Level 1

                                      I have Acrobat Pro 9 and I can't find a separate reader installation.

                                      • 17. Re: Launch PDF from HTML and execute search
                                        George_Johnson MVP & Adobe Community Professional

                                        I may be getting thrown off track by your use of the term "Reader". Are you testing this with Adobe Reader or just Acrobat? I've been assuming that you're testing with both, and that it's working with Acrobat but not Reader. It now sounds like you're just using Acrobat and that it works when opened directly in Acrobat, but not when Acrobat is used to display the document in the browser.

                                        • 18. Re: Launch PDF from HTML and execute search
                                          tygr Level 1

                                          That's correct, sorry for the confusion.  It doesn't work when the PDF is launched from the browser, even when Acrobat is forcing the display to Acrobat via the preferences.  Thanks for your time on this.  The Adobe PDF JS reference says that the search.query function can only be run through the console or as a batch process when the index parameter is used.  This must only come into play with the security sandbox that is used when the PDF is launched from a browser, since the script works when the PDF is loaded directly into Acrobat.  We are going to punt on this.  Thanks again for your help.  Jon