9 Replies Latest reply on Oct 9, 2009 7:09 PM by Funnyvoyage

    trustedFunctions

    mattrichards Level 1

      I have created a button on the toolbar with which I am trying to do some really simple stuff:

       

      - Copy the contents of the active doc

      - Create a new doc

      - Paste the contents of the original doc into the new one

      - do a saveAs on the new doc

      - then close the new doc

       

      Two questions:

       

      1. Anyone know a quick and easy mechanism for duplicating the active document without creating a new blank doc and then copying the contents into that?

       

      2. I am getting a lot of NotAllowedErrors. I figured out that the newDoc and saveAs functions had to be recreated as trustedFunctions with trustPropigatorFuctions ( http://forums.adobe.com/message/2302487 ). I read the API for this and got it working. My questions is, why is this? Perhaps there is something else I can do that is more straightforward than rewriting this stuff?

       

      Thanks for all of your help.

       

      Matt

        • 1. Re: trustedFunctions
          try67 MVP & Adobe Community Professional

          First of all, you can't paste the contents of a PDF into a new file using JavaScript.

          I don't understand why not simply save as a copy, as you did before? That's the best (and probably only) way of doing it.

          About the not allowed errors: Adobe made the security restrictions much tougher in the last version of Acrobat. Unless you use an earlier version there's no way around it.

          • 2. Re: trustedFunctions
            mattrichards Level 1

            Apologies for the way I described that process. I did not mean to

            suggest that it was as straight forward as a copy/paste.

             

            The issue is that I need the saveAs process to be entirely hidden from

            the user. If I do a straight saveAs to their existing document, they

            are left with the new doc still open in Acrobat. I do not want this. I

            want to leave them in the state at which they entered this process -

            with their original doc open and unmodified.

             

            Matt

            • 3. Re: trustedFunctions
              try67 MVP & Adobe Community Professional

              Then you need to do a saveAs, then close the file and then re-open the

              original.

              • 4. Re: trustedFunctions
                mattrichards Level 1

                Thanks again for responding. I appreciate your time and expertise.

                 

                I've been thinking about that exact approach. I'm going to give it a

                go shortly. My only concern is how smooth that process will be, but I

                guess I'll find out!

                 

                Thanks again.

                 

                Matt

                • 5. Re: trustedFunctions
                  Vaibhav Padlikar Level 2

                  You may use bCopy option set to true, by default it's false.

                   

                  -vaibhav

                  • 6. Re: trustedFunctions
                    mattrichards Level 1

                    bCopy! This is exactly what I needed.

                     

                    Thanks!

                     

                    Matt

                    • 7. Re: trustedFunctions
                      mattrichards Level 1

                      Unfortunately, I keep running into NotAllowedErrors, even when trying to do very simple stuff.

                       

                      I have a JS here: C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Javascripts

                       

                      Which runs at application launch. It adds a button to the toolbar, which when pressed saves a copy of the open document to a network location. Pretty easy. I'm just trying to get it to open an existing PDF right after it's done so, and I am getting the NotAllowed Error.

                       

                      app.openDoc("/d/flow/billing.pdf");

                       

                      I'm suprised to see that such a simple call is yielding that error. Might it be because it's being called from a toolbar button? It seems to me that opening a PDF should probably be pretty straight forward, and my difficulty suggests to me that I'm doing something incorrectly.

                       

                      In order to do a saveAs, I had to write a trustedFunction and a trustPropigatorFunction as well (this too seems severe). I tried doing this for the app.openDoc call and I still got the errors.

                       

                      Why would app.openDoc throw NotAllowedErrors? Could these method calls be made in a way where they are trusted by default?

                       

                      Thanks for your thoughts. Apologies for my rudimentary understanding of security and Acrobat JS generally. I really appreciate your time.

                       

                      Matt

                      • 8. Re: trustedFunctions
                        try67 MVP & Adobe Community Professional

                        openDoc shouldn't have as many security restrictions as saveAs... try running this same line from the console and see if that works.

                        If not, then maybe there's a problem with the code itself.

                        • 9. Re: trustedFunctions
                          Funnyvoyage Level 1

                          Thanks for your imformative tips. They are all helpful.