12 Replies Latest reply on Sep 29, 2009 8:57 PM by Vanorobat

    open file using Javascript

      I am trying to open a file using a javascript dropdown menu. I know acrobat allows users to open a single file using the standard features, but I have about 30 different files that need to be referenced. the general idea is currently;

      window.open("C:\Documents and Settings\Desktop\" + event.value + ".pdf");

      Besides the fact it doesn't work at all, I'm getting an error message "unterminated string literal". This is due to the \ right before the end of the directory string. but I cannot think of a way to finish the directory string without using this methoid. (i've also tried assigning the '\' to it's own variable but that is throwing the same error. if you have any idea, please let me know. I may have fixed this issue, i'm using \\ instead of \ after Desktop, but the file still will not open. I've also tried using app.launchURL to no avail. please help me with another open command, please.
        • 1. Re: open file using Javascript
          Bernd Alheit Adobe Community Professional & MVP
          You can use the openDoc method. Details in the Acrobat JavaScript Reference.
          • 2. Re: open file using Javascript
            George_Johnson MVP & Adobe Community Professional
            You need to use the app.openDoc method, and specify the path correctly, something like:

            "/c/Documents and Settings/Desktop/"

            The Acrobat JavaScript reference has more information.

            George
            • 3. Re: open file using Javascript
              Level 1
              hi, i'm using the app.openDoc methoid and don't seem to be getting anywhere. i've read a few forums that say that only works with Acrobat 7. I'm on Acrobat 8. I'll keep researching, but if someone has another answer for me I would appreciate it.

              verbatum line;

              app.openDoc("\C:\Documents and Settings\Admin\Desktop\\" + event.value + ".pdf");
              • 4. Re: open file using Javascript
                try67 MVP & Adobe Community Professional
                Replace all the back slashes with forward slashes, drop the colon and the extra slash at the end, like so:

                app.openDoc("/C/Documents and Settings/Admin/Desktop/" + event.value + ".pdf");
                • 5. Re: open file using Javascript
                  gkaiseril MVP & Adobe Community Professional
                  I believe the Acrobat JavaScript API Reference has examples. like:

                  var otherDoc = app.openDoc("/c/temp/myDoc.pdf");
                  otherDoc.getField("name").value="Enter your name here: "
                  otherDoc.getField("name").setFocus();
                  this.closeDoc();

                  Note there is no ":" and the "/" delimiter is used.

                  So you would create your statement like:

                  app.openDoc("/C/Documents and Settings/Admin/Desktop/" + event.value + ".pdf");
                  • 6. Re: open file using Javascript
                    Level 1
                    still no luck, i copied the line you added, and it doesn't even think about it now (when i had what i listed there was a bit of a delay then nothing happened)

                    I've checked the file extension and names MANY times already (because i often make stupid mistakes like that) and all is correct, even case sensitive correct. I am using Acrobat 8, not sure if that makes app.openDoc useless or not. please let me know. Thank you
                    • 7. Re: open file using Javascript
                      Level 1
                      actually... i figured it out. I was using .txt files as a basis for the testing (as the 30 someodd PDF files have not yet been created. Turns out, you cannot open a .txt file, but CAN open a PDF. Thanks very much for all the help!! Saved me hours of useless struggle. (don't ask how I came about to create a random pdf and check that, just a random moment I had)
                      • 8. Re: open file using Javascript
                        normynorms Level 1

                        var otherDoc = app.openDoc("/c/temp/myDoc.pdf");
                        otherDoc.getField("name").value="Enter your name here: "
                        otherDoc.getField("name").setFocus();
                        this.closeDoc();

                         

                        this code doesnt work wen i hav changed it to suit my needs.(interms of the document name)

                         

                        placed it in a catch block it returned otherDoc doesnt has no properties.

                         

                        could you assist me please really need the help with this.

                        • 9. Re: open file using Javascript
                          try67 MVP & Adobe Community Professional

                          Do you have a file with that name in that location? Is it being opened?

                          • 10. Re: open file using Javascript
                            Bernd Alheit Adobe Community Professional & MVP

                            Did you set property disclosed of the document?

                            • 11. Re: open file using Javascript
                              Vanorobat

                              Do I have to specify a full path?  Can I have it link to a document located in the same folder as the document I'm creating the link in, as a relative reference?  I just want navigation buttons that link to other PDF documents in the same folder.  Eventually the PDFs will all be moved to another location on a server and accessed via the web.  But I do not know the path of that location.

                              • 12. Re: open file using Javascript
                                Vanorobat Level 1

                                ok I actually figured out the syntax for opening a document in the same folder with no path.  But it opens it in a new window.  I would really like it to open in the same window as my original document, just like it would if I were to use the "open a file" command and select "existing window".  The reason I'm not just doing that is because I have to create ALOT of PDFs with links to each other and when I copy a control between PDFs it doesn't bring over the actions for the control except for javascript.  If I use javascript, its easy for me to just change one or two names of the file references rather than having to renavigate to all the files I'm linking when I start a new document.

                                 

                                This is my basic code to open a file:

                                 

                                app.openDoc("TemplateTest1.pdf", this);

                                 

                                Its placed on the mouse up event of a control. I thought the "this" part meant this window but I guess it doesn't since it opens the file in a new window.

                                 

                                The final version of this document will be accessed via internet explorer on a corporate intranet.  when I open the document in internet explorer and execute the openDoc script, it opens the acrobat application as a new window while the original document remains in internet explorer.  I want the new document, which is saved in the same location as the original, to replace the original document in internet explorer.  I have done this before via bookmarks by assigning an open file action and specifying it to open in the existing window.  I just dont know how to specify that instruction in javascipt.

                                 

                                Or if for some reason this isn't possible.  Can I use the javascript to redirect internet explorer's address to the new document?  If I do it this way I will need to get the address and then replace the exisiting file name with the new file name I want to link to.  Is this possible.  I'm interested in learning about both methods.

                                 

                                Sorry If Its rediculously basic.  I am just learning javascript specifically for this PDF project.