14 Replies Latest reply on Mar 22, 2009 1:49 PM by C.Sarelius

    From link open Explorer window to display files

    C.Sarelius
      Hi,

      I'm using Acrobat 8 Pro. I have a PDF with links to a number of other PDFs - I'm happy doing this with normal Acro JS. What I also want to do is create a link that, when clicked, will open an instance of Windows Explorer that will display the files in a folder located on a CD. I've tried using the window.open() method but I think I'm doing something wrong.

      Could someone please point me in the right direction or provide a clue to what I should be doing, assuming it can be done.

      Advice appreciated.

      Carl
        • 1. Re: From link open Explorer window to display files
          Patrick Leckey Level 3
          window.open() doesn't exist in AcroJS - the "window" object is defined by your browser, so it is not part of Acrobat JavaScript.
          • 2. Re: From link open Explorer window to display files
            C.Sarelius Level 1
            Thanks PDL,

            I'm aware the open() method is not part of Acro JS but it is part of the core JavaScript and my understanding is that core JS can be used in a PDF also.

            Any ideas?

            Thanks

            Carl
            • 3. Re: From link open Explorer window to display files
              Bernd Alheit Adobe Community Professional & MVP
              window.open() isn't part of the core JavaScript.
              • 4. Re: From link open Explorer window to display files
                Patrick Leckey Level 3
                Carl,

                Not sure where you got your info, but the "window" object is not part of core JS. It is provided by your browser, for your browser, only for use in your browser.
                • 5. Re: From link open Explorer window to display files
                  C.Sarelius Level 1
                  Hi guys,

                  thanks for that, point taken. I got the information from w3schools.com (http://www.w3schools.com/htmldom/met_win_open.asp) but after reading your comment, I went back and realise I misinterpreted the examples and what was being said. I thought that I could access Windows Explorer by using the same function - I was wrong.

                  Back to square one. Any ideas how I could open an instance of Windows Explorer from within a PDF?

                  Cheers

                  Carl
                  • 6. Re: From link open Explorer window to display files
                    try67 MVP & Adobe Community Professional
                    If Internet Explorer is set as the default browser, this might do the trick (you can change the string to point to whichever folder you want):

                    app.launchURL("file://C:/");
                    • 7. Re: From link open Explorer window to display files
                      Patrick Leckey Level 3
                      launchURL will not allow a file:// reference for security reasons. This is documented clearly in the API Reference.

                      You can use app.launchURL to open a link to a PDF hosted on the web somewhere, and if you want it to open in the system default browser (not necessarily IE, it will just use the system default) make sure you set the 2nd parameter to true.

                      app.launchURL("http://my.server.com/path/to/file.pdf", true);
                      • 8. Re: From link open Explorer window to display files
                        try67 MVP & Adobe Community Professional
                        PDL, did you try it? My guess is that you didn't, because it works.
                        I tried it using both Acrobat 8 Pro and Reader 9, and it worked in both.
                        • 9. Re: From link open Explorer window to display files
                          Patrick Leckey Level 3
                          Do you have your local system set as a trusted location in your Acrobat preferences or are you running it from a folder-level JavaScript? That is not what he was asking for ...

                          I just added a button to a blank form, only script on the button is:

                          app.launchURL("file://c/temp/host.txt");

                          When clicked, the JS Console shows:

                          NotAllowedError: Security settings prevent access to this property or method.
                          App.launchURL:1:Field Button1:Mouse Up

                          (Acrobat 9.1 Pro Extended)

                          See the documentation at:

                          http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/JS_API_AcroJS.88.150.html

                          It specifically says:

                          Note: Beginning with Acrobat 8.1, File and JavaScript URLs can be executed only when operating in a privileged context, such as during a batch or console event. File and JavaScript URLs begin with the scheme names javascript or file.

                          Even if it was a bug and it did work (which it isn't since it works as documented), why would you recommend something that is forbidden by the documentation? As of any future update it could stop working and break the workflow, making him have start all over again with a different method.
                          • 10. Re: From link open Explorer window to display files
                            try67 MVP & Adobe Community Professional
                            Until now I ran it from the console, but after your message I've put it in a folder-level script, and it worked as well.

                            The reason I provided him with this information is that it's the only solution to his problem. It's up to him to decide whether to use it or not. Anyway, I wasn't aware that this was "forbidden by the documentation", which is obviously irrelevant since it's working.
                            • 11. Re: From link open Explorer window to display files
                              Patrick Leckey Level 3
                              > Anyway, I wasn't aware that this was "forbidden by the documentation", which is obviously irrelevant since it's working.

                              Not irrelevant at all, in fact you just explained why it's working for you but won't work from a document-level script. Running script from the console runs it in an elevated security context which is why it's working for you, but won't work if you add "app.launchURL" directly to a button.

                              Please see the security documentation in the SDK. A "priviledged context" is a batch, console or app init event.

                              You have just showed that it works from a console and an app init (which is when folder-level JavaScripts are processed) event, which the documentation says WILL work - so the documentation is correct here.

                              Add you script to a button as I showed above and click the button. It won't work - security restricted, exactly as I and the documentation have been saying. Again, documentation correct.

                              It would probably be wise of you to familiarize yourself with the security contexts of Acrobat JavaScript as many, many functions in Acrobat JS will run from the console and seem to work, but then be security restricted and fail when you put them in a document-level script.

                              So in a sense you're right - it's a matter of implementation. If it's a scenario where he can tell his users to run script from the console or to install a .js file to their Acrobat\JavaScripts folder, it will work.

                              If the form will be distributed to users who's machines you have no control over and who aren't going to open the console and run the script, meaning it has to be in a document-level script, it will not work.
                              • 12. Re: From link open Explorer window to display files
                                try67 MVP & Adobe Community Professional
                                OK, so we agree that it can work under *some* circumstances.
                                I'm very familiar with the different security contexts of Acrobat, maybe I didn't pay enough attention to the fact that he wants to run it from a link.
                                • 13. Re: From link open Explorer window to display files
                                  Patrick Leckey Level 3
                                  > OK, so we agree that it can work under *some* circumstances.

                                  Yup. :)
                                  • 14. Re: From link open Explorer window to display files
                                    C.Sarelius Level 1
                                    Thanks PDL, thanks try67,

                                    your feedback and discussion is much appreciated. Try67, I haven't been able to get this to work yet, my results being the security error that PDL mentioned.

                                    I need to do a bit more study. I'm trying to keep this as simple as possible by keeping the scripts in the document (i.e. the scripts are part of the link I put in), therefore not having to refer to external scripts in a folder, but if I have to I'll create external scripts. The document I'm working on will be delivered on a CD together with the files that I want displayed in a folder.

                                    Thanks again for your help.

                                    Cheers