11 Replies Latest reply on Feb 10, 2011 2:39 PM by maxwyss

    More about app.openDoc

    frankrenner2011 Level 1



      being a bit further with my work on app.openDoc thanks to the help of this forum, I'm a bit puzzled about the following problem:


      var mainDoc = app.openDoc(mainDocPath);

      //var mainDoc = app.openDoc("/C/myDoc.pdf");



      In this example "mainDocPath" is a valid path and the document opens. Anyway mainDoc is being evaluated as "undefined".

      When I use the commented line instead, the alert displays "[Doc_Object]" as I would expect.


      What is going wrong here?


      Thanks for any help.

        • 1. Re: More about app.openDoc
          try67 MVP & Adobe Community Professional

          There must be something else amiss. Are you sure the value of mainDocPath is

          EXACTLY the same as the other value? Does the file actually open?

          • 2. Re: More about app.openDoc
            frankrenner2011 Level 1

            App.openDoc is quite a mess in any way. Probably once one has solved all the problems around it, everything is easy and running forever but as long as one has to work for days just to get a simple example running it is quite frustrating. I checked the following:


            1. I can open a document at a simple path like "/C/myDoc.pdf". It also opens when I assign the simple path to a variable like "mainDocPath". If I have a path like "/C/Dokumente und Einstellungen/Administrator/Eigene Dateien/2-02-05-0000-0007 R001.pdf" in the variable I get the "NotAllowedError". I already tried to surround the path variable with quotation marks as I already experienced that Windows is a bit cheeky with blanks and other special characters. Anything else I would have to take into consideration?


            2. I can call the simple path from a buttons mouse up event. But what I actually want to do is start a control document, which I want to open the target document, place a few form fields, fill them from the database and quit itself. Apart from point 1, this already works well with a simple path and a mouse up event in a button. But when I take the method from the buttons mouse up event to a document level script, I get the "NotAllowedError" again. Why that?


            Thank you for the answers, also those referring to other threads.

            • 3. Re: More about app.openDoc
              try67 MVP & Adobe Community Professional

              It's possible that the file you're trying to open is not in a "safe" path

              (ie. it is in some kind of protected system folder), and therefore Acrobat

              refuses to open it via a script. Unfortunately, there is no documentation of

              what is a safe path and what isn't.

              This could explain the behavior you're describing in point 1.

              About point 2, I'm not sure what to tell you. According to the reference

              this method should run from a document-level script as well as from a button

              action (which has less privileges than a doc-level script anyway). Maybe the

              problem there is the same as in point 1.

              • 4. Re: More about app.openDoc
                frankrenner2011 Level 1

                I have been breaking down complexity a bit further.


                Two documents: C:\Control.pdf and C:\Main.pdf.


                The control document has a document level javascript "TestCall" with content:


                function TestCall() {

                    mainDoc = app.openDoc("/C/Main.pdf");




                The main document has a javascript "SetDisclosed" with content:
                function SetDisclosed()
                    this.disclosed = true;
                When I run the control javascript while the document is open, everything is fine and it opens the main document. If the javascript runs on document initialization, I get the "NotAllowedError".
                If I change the line "mainDoc = app.openDoc("/C/Main.pdf");" to "mainDoc = trustedOpenDoc("/C/Main.pdf");", i.e. running the folder level script
                trustedOpenDoc = app.trustedFunction(
                     function(pPath) {
                          var trustedDoc = app.openDoc({
                               cPath: pPath,
                               bUseConv: true
                everything is still fine when run from the opened control document.
                When it runs at document initialization, I get an error dialog stating that an error occurred when opening the document because of an "invalid action object" (this is in german language and I don't know the exact words that it will show in an english language version).
                That can't be the intended way of functionality, can it? When reading through the forums, I get a feeling like many people do what I want to do and there is only one more little hint missing and there will be prospering landscapes for my programming efforts if this could be solved. Unfortunately I can't find the point myself and can't see sense and meaning in that ugly behaviour.
                I already had the idea that the folder level scrips might not already be loaded when the trusted function is called at document initialization and tried it in a loop with a try/catch construction, but it was never working at document initialization.
                Any more hints?

                • 5. Re: More about app.openDoc
                  try67 MVP & Adobe Community Professional

                  You're not calling SetDisclosed so Main.pdf is not actually disclosed.

                  Either call it from the same document-level script, or simply place the

                  this.disclosed=true line outside of any functions.

                  • 6. Re: More about app.openDoc
                    frankrenner2011 Level 1

                    Yes, thank you, stupid me...but...same result after I corrected this, no change in behaviour :-(.

                    • 7. Re: More about app.openDoc
                      gkaiseril MVP & Adobe Community Professional

                      Any PDF that your are going to open with the 'app.openDoc()' method, needs a document level JavaScript statement that sets that documents 'disclosed' document property to 'true'. Add the following script as a document level script in the PDF you are attempting to open:


                      this.disclosed = true;


                      Do not have that code inside a function.





                      The disclosed property can only be set during batch, console, Page/Open and Doc/Open events. See the event object for a discussion of JavaScript events. See also "Privileged versus non-privileged context" on page 32.



                      Specifies whether the document should be accessible to JavaScript scripts in other documents.


                      app.openDoc and app.activeDocs methods check the disclosed property of the document before returning its Doc.



                      Example 1

                      A document can be disclosed to others by placing the code at the document level (or as a page open action) at the top level:

                      this.disclosed = true;


                      Example 2

                      The following code can be used in an Execute JavaScript Batch Sequence to disclose all selected documents.

                      this.addScript("Disclosed", "this.disclosed = true;");


                      • 8. Re: More about app.openDoc
                        frankrenner2011 Level 1

                        I have already corrected this, but still have the unwanted ugly behaviour that I was describing, which means the "Main" document opens properly when the script is run from the already opened "Control" document, but not on initialization of the "Control" document so that I could do what I want, namely setting up the main document from the control document and afterwards quit the control document immediately.

                        • 9. Re: More about app.openDoc
                          gkaiseril MVP & Adobe Community Professional

                          Have you read the section in the Acrobat JS API Refrence about the use of paths?




                          Safe path


                          Acrobat 6.0 introduced the concept of a


                          safe path for JavaScript methods that write data to the local hard drive based on a path passed to it by one of its parameters.

                          A path cannot point to a system critical folder, for example a root, windows or system directory. A path is also subject to other unspecified tests.


                          For many methods, the file name must have an extension appropriate to the type of data that is to be saved. Some methods may have a no-overwrite restriction. These additional restrictions are noted in the documentation.


                          Generally, when a path is judged to be not safe, a


                          NotAllowedError exception is thrown (see Error object) and the method fails.

                          • 10. Re: More about app.openDoc
                            frankrenner2011 Level 1

                            Yes, I have read this chapter and I can say that if anything is wrong with the path, the NotAllowedError exception is thrown, not only if it's not safe. For example, if I would try to app.openDoc("NoCorrectPathName"), I would get the NotAllowedError exception. I also found out that a quoted string as a pathname helps avoiding the NotAllowedError (that I would otherwise get under nearly all circumstances, explicitly if I have blanks or dots in the pathname).


                            But I actually do have a pathname to a file that can easily be opened by app.openDoc from a button, but never at document initialization time (which is the time I need to do it).


                            To me it looks like this issue can not be solved. So I tried a workaround:


                            From my database, I open BOTH documents, the Control document and the Main document. Then I sort out which is which by looping through app.activeDocs array and get a valid object for the Main document, which I can easily use this for my manipulations before closing the Control document. This works fine and without any problems comparable to using app.openDoc.


                            Thank you for your support and all the very professional answers to my questions in this thread.

                            • 11. Re: More about app.openDoc
                              maxwyss Level 4

                              A few semi-related comments, to this and previous messages:


                              a) It might be an idea to try to open the main document from the PageOpen event of the opening page of the Control document, instead from a document-level script. My experience has shown that there may be timing issues when doing things from the document-level scripts.


                              b) Acrobat 9 and 10 have a serious bug when opening a document using openDoc(). When the file path is not existing (as it happens when the file does not exist), the "notAllowedError" is thrown, instead of the "filePathError" (you would get in Acrobat 8 and earlier). This has been reported several times, but it has not yet been fixed.