12 Replies Latest reply on Jun 30, 2011 10:37 PM by try67

    app.openDoc behaves erratically concerning "security access"

    Joe The Engineer

      I use the following line in a document level function:

       

      app.openDoc({ cPath: WhatFile , cDest: WhatPage });

       

      WhatFile is a string representing a filename in the same folder as the PDF this code is working in.

      WhatPage is a destination inside the PDF I'm going to open.

       

      For some reason, half of the time it gives me a security access violation when I run the script and the other half of the time it works perfectly.  I've made sure that every document in the folder has "this.disclosed" set by setting it as such in the document level code (it's not in a function, so it apparently should run every time the document opens.)  What really stumps me is that I'm not changing anything about the scenario between the times that it fails and the times that it works.  i have multiple files set up to do this and it won't work for several minutes straight.  It will keep giving me the same error; and then, all of a sudden it starts working without me changing a thing. 

       

      Here's what really stumps me about it:

      1) All of my documents are disclosed, so I shouldn't be getting the security access restriction message in the first place.

      2) my openDoc method is assigning a destination, which I believe I read in the scripting guide means that the documents don't have to be disclosed.

       

      Does anyone have a clue as to why it would work sometimes and then not at others?

       

      See this link for reference:  http://forums.adobe.com/message/3766053#3766053

      I would have continued in that thread, but it was already listed as answered.

        • 1. Re: app.openDoc behaves erratically concerning "security access"
          try67 MVP & Adobe Community Professional

          Is your script "this.disclosed" or "this.disclosed = true;" ? It should be

          the latter.

          Are you getting any error messages in the console? If so, which ones?

          • 2. Re: app.openDoc behaves erratically concerning "security access"
            Joe The Engineer Level 1

            i'm using "this.disclosed = true;"

             

            the error message in the console is this:

             

             

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

            App.openDoc:4:Field 2_Mechanical:Mouse Up

            One thing to note is that when it happens, it is consistently giving me the error for a period of time...then all of sudden it works consistently for a period of time...

             

            I'm wondering sometimes if it doesn't realize that the file i'm trying to open is in the very same folder.

            • 3. Re: app.openDoc behaves erratically concerning "security access"
              George_Johnson MVP & Adobe Community Professional

              That's odd, and not something I've experienced. Just as a test, what happens if you leave out the cDest parameter?

              • 4. Re: app.openDoc behaves erratically concerning "security access"
                Joe The Engineer Level 1

                I'll let you know as soon as it stops working again.  It is currently working (I haven't changed anything.)  Is there a chance that it is just slow is assigning something as being a "safe path"?  I'm trying to remember if I've experienced a time where it didn't evenutally work if I left files in the same location for long enough.  While reading through the API reference I notice that with anything after Acrobat 8.0, I shouldn't have to use the "this.disclosed = true;" statement.  The most peculiar thing about all of this is that it seems to fix itself without me modifying anything.  If it acts up again, i'll post what happens when leaving out the cDest parameter.

                 

                I just had an idea that maybe i should try to declare every parameter in my open method to see if one of them is getting toggled somehow...

                 

                 

                Also, for some reason, Acrobat crashes EVERY time I try to step through any code.  I don't know why.  Windows just says the application stopped working correctly and had to be shut down.  BTW, my code is in a button javascript that references a function.  Currently, it isn't working at all from Adobe Reader but is working from Acrobat.  Previous references to it not working were in the environment of Acrobat. 

                • 5. Re: app.openDoc behaves erratically concerning "security access"
                  Joe The Engineer Level 1

                  Here's the full console feed:

                   

                   

                  Exception in line 4 of function OpenFileAtPage, script Document-Level:OpenFileatPage

                  Exception in line 1 of function top_level, script AcroForm:2_Mechanical:Annot1:MouseUp:Action1

                   

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

                  App.openDoc:4:AcroForm:2_Mechanical:Annot1:MouseUp:Action1

                  Here is all of my code from opening "Edit All Javascript", but basically I have only one button with any code in it.

                  //-------------------------------------------------------------
                  //-----------------Do not edit the XML tags--------------------
                  //-------------------------------------------------------------

                  //<Document-Level>
                  //<ACRO_source>OpenFileatPage</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: Document-Level:OpenFileatPage ***********/


                  function OpenFileAtPage(WhatFile,WhatPage)
                  {

                  app.openDoc({ cPath: WhatFile , cDest: WhatPage });
                  }


                  //</ACRO_script>
                  //</Document-Level>

                  //<Document-Level>
                  //<ACRO_source>disclosure</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: Document-Level:disclosure ***********/

                  this.disclosed = true;


                  //</ACRO_script>
                  //</Document-Level>

                  //<AcroForm>
                  //<ACRO_source>2_Controls:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_Controls:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_Electrical:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_Electrical:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_FireProtect:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_FireProtect:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_FoodSvc:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_FoodSvc:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_Mechanical:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_Mechanical:Annot1:MouseUp:Action1 ***********/
                  OpenFileAtPage("2_Mechanical.pdf", "Mech");
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_MedGas:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_MedGas:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_Plumbing:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_Plumbing:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_Sterilization:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_Sterilization:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>

                  //<AcroForm>
                  //<ACRO_source>2_VerticalTrans:Annot1:MouseUp:Action1</ACRO_source>
                  //<ACRO_script>
                  /*********** belongs to: AcroForm:2_VerticalTrans:Annot1:MouseUp:Action1 ***********/
                  // Put JavaScript Here
                  //</ACRO_script>
                  //</AcroForm>
                  • 6. Re: app.openDoc behaves erratically concerning "security access"
                    try67 MVP & Adobe Community Professional

                    You can't call openDoc from a doc-level script directly. It must run from a

                    trusted context (ie from a folder-level script).

                    • 7. Re: app.openDoc behaves erratically concerning "security access"
                      Joe The Engineer Level 1

                      If that is true, then why does it work half of the time?

                       

                      I also have my paths set as trusted in security settings....

                      • 8. Re: app.openDoc behaves erratically concerning "security access"
                        George_Johnson MVP & Adobe Community Professional

                        If you're not specifying the complete path, you should include the oDoc parameter, which is given by "this".

                        • 9. Re: app.openDoc behaves erratically concerning "security access"
                          Joe The Engineer Level 1

                          George,

                          I believe you may have hit the nail on the head.  I was trying to execute the same code in 3 different documents.  None of them were working (although all of them had previously worked.)  I specified "oDoc = this" in my open method in each of them and they all opened accordingly.  I read somewhere that relative references were better than specific references to a drive and that if you just indicate a filename that it assumes the relative drive location to be the same folder as current document.  Now I believe that idea is subject to scrutiny. Maybe it references the last drive location according to a query that it runs every so often or maybe it references the "current drive's" "current path" handed to it by windows which may or may not coincide with the open document.  Either way, it is working now that I specified that parameter.   (I actually mentioned earlier that I thought maybe I should specify every parameter and failed to do it until you recommended it

                           

                          Thanks, and hopefully that solves the issue.  I'll give it the test of time before i check "yes, this has been answered." 

                          • 10. Re: app.openDoc behaves erratically concerning "security access"
                            maxwyss Level 4

                            It may or may not be relevant for this question, but in Acrobat 9 (and most likely 10), the message appearing when you try to open a wrong path (meaning tht the document does not exist) is plain wrong. The message says something about security restrictions not allowing this method. But it should simply say that the document can not be found. You may try to do the same in Acrobat 7, and you will see the difference.

                             

                            So, there is a chance that the path of the document to be opened is not correct.

                             

                            Hope this can help.

                             

                            Max Wyss.

                            • 11. Re: app.openDoc behaves erratically concerning "security access"
                              Joe The Engineer Level 1

                              maxwyss,

                               

                              in essence, that is what was happening.  It must have been referencing a folder as the relative folder which didn't have my file in it.   George's comment to specify oDoc in the open method resolved the path problem.  Theoretically, the path problem shouldn't have existed b/c the relative referencing should have used the same path as the document calling the method, but for whatever reason, that only seemed to happen about half of the time.

                              • 12. Re: app.openDoc behaves erratically concerning "security access"
                                try67 MVP & Adobe Community Professional

                                Sorry, my bad. Was confused with the method to save a file.