11 Replies Latest reply on Jul 10, 2014 9:45 AM by try67

    doc.saveAs() and trusted function

    MatLac Level 1

      About three years ago, I posted on this forum a question about creating a trusted function to save to a specific location.  I cannot find the original post.  I remember at that time I was looking for a way to save to the user's desktop folder which path changes from user to user.  Somebody came up with this:

      myGetPath = app.trustPropagatorFunction(function(v1,v2){

      app.beginPriv();

      return app.getPath(v1,v2);

      app.endPriv();

      });

      myTrustedGetPath = app.trustedFunction(function(v1,v2) {

      app.beginPriv();

      return myGetPath(v1,v2);

      app.endPriv();

      });

       

      safeSaveAs = app.trustPropagatorFunction(function(doc,vPath){

      app.beginPriv();

      doc.saveAs({cPath:vPath});

      app.endPriv();

      });

      myTrustedSaveAs = app.trustedFunction(function(doc,vPath){

      app.beginPriv();

      safeSaveAs(doc,vPath);

      app.endPriv();

      });

       

      After reading throught the API reference and this tutorial, I don't understand the difference between the trusted function and the trust Propagator function or why I need a trust propagator.

       

      What I need now is to save to a predetermined folder so I guess I can drop the getPath part.

        • 1. Re: doc.saveAs() and trusted function
          try67 MVP & Adobe Community Professional

          I believe this code was written by me...

           

          What trustPropagatorFunction does according to the API, is:

          Marks a function as a trust propagator. Such a function is not itself trusted but can inherit trust if called from a trusted function.

           

           

          If you want to use a fixed folder just hard-code it into your script when you call myTrustedSaveAs. For example:

           

          myTrustedSaveAs(this, "/c/temp/" + this.documentFileName);

           

          This will save the file under the same name, but in the C:\Temp\ folder.

          • 2. Re: doc.saveAs() and trusted function
            MatLac Level 1

            I believe so too, lol.  You always find the right answers.

             

            I read the definition of trust propagator but don't undestand what exactly it does.  From what I understand, calling only this would work just as well, wouldn't it?

             

            myTrustedSaveAs = app.trustedFunction(function(){

            app.beginPriv();

            doc.saveAs({cPath:"C\temp\folder\"+this.documentFileName});

            app.endPriv();

            });

             

            Also.  My organisation is not quite fond about the idea of putting whatever script in a program folder as it is a highly secure organisation.  I don't have the necessary clearance for doing it myself and needs to convince IT departement that it is secure.

             

            Are there any risks associated with this function other than someone could call the function (assuming he knows it exists) to save any file to that folder, lets say a malicious sofware?

             

            Anyway to make it more secure or add an extra layer of protection or parameter?  We already have a 2-step process to login into the computer so we don't want an extra password.  I was thinking maybe I could use a regular expression to verify a pattern file name as well as extension, maybe set size parameters for acceptable files.  The target folder will be exclusively used for that.

            • 3. Re: doc.saveAs() and trusted function
              try67 MVP & Adobe Community Professional

              Read the API for the full description of what it does. It might work without it, but I suggest leaving it in.

               

              Your cPath variable has an incorrect value. Use the same syntax as I did in my example above. Also, do not use the "this" object in a trusted function. That's why you're passing the "doc" object as a parameter to it.

               

              I really don't see any security risks with this method. All it can do is save a document in this folder... Nothing else.

              • 4. Re: doc.saveAs() and trusted function
                MatLac Level 1

                to sum it up, I place this in the folder:

                 

                safeSaveAs = app.trustPropagatorFunction(function(doc){

                app.beginPriv();

                doc.saveAs({cPath:"\\folder\Temp."+this.documentFileName});

                app.endPriv();

                });

                myTrustedSaveAs = app.trustedFunction(function(doc,vPath){

                app.beginPriv();

                safeSaveAs(doc,vPath);

                app.endPriv();

                });

                 

                 

                and I call the function from anywhere with:

                 

                myTrustedSaveAs()

                 

                Am I right?

                • 5. Re: doc.saveAs() and trusted function
                  try67 MVP & Adobe Community Professional

                  No, your path is still incorrect. Look carefully at the code I provided or read the official PDF Reference to see how you should specify device-independent paths.

                  • 6. Re: doc.saveAs() and trusted function
                    try67 MVP & Adobe Community Professional

                    Also, remove the vPath parameter from myTrustedSaveAs (and from the call to safeSaveAs), since you're not doing anything with it anyway.

                    • 7. Re: doc.saveAs() and trusted function
                      MatLac Level 1

                      I didn't notice slashes were on the other side.  I need to force the file name to reflect the value of a particular field.  Would it be the way to do it?

                       

                      safeSaveAs = app.trustPropagatorFunction(function(doc,fieldValue){
                      app.beginPriv();
                      doc.saveAs({cPath:"/c/temp/"+fieldValue+".pdf"});
                      app.endPriv();
                      });
                      myTrustedSaveAs = app.trustedFunction(function(doc,fieldValue){
                      app.beginPriv();
                      safeSaveAs(doc,fieldValue);
                      app.endPriv();
                      });

                       

                       

                      and I call the function from anywhere with:
                      myTrustedSaveAs(this, fieldValue)

                      • 8. Re: doc.saveAs() and trusted function
                        try67 MVP & Adobe Community Professional

                        Yes, that looks better. However, using the value of a field is tricky as it could be empty or contain illegal characters...

                        • 9. Re: doc.saveAs() and trusted function
                          MatLac Level 1

                          Custom keystroke and validation for this field will take care of this.  I'll also make sure the field is not empty when calling the function.

                           

                          Thanx for the quick response.

                          • 10. Re: doc.saveAs() and trusted function
                            lindaeliseruble Level 1

                            Hello Gilad,

                             

                            I'm using the following code and receiving a "SyntaxError: missing formal parameter" error

                             

                            myOpenDoc = app.trustPropagatorFunction(function(doc,"/C/CustomPDFSearch/Input Page2.pdf"){

                            app.beginPriv();

                            return app.openDoc({cPath: vPath});

                            app.endPriv();

                            });

                             

                            Please let me know what I am doing wrong.

                             

                            thanks

                             

                            Linda

                            • 11. Re: doc.saveAs() and trusted function
                              try67 MVP & Adobe Community Professional

                              You're entering the actual values where you should be entering the names of

                              the parameters for the function.

                               

                               

                              On Thu, Jul 10, 2014 at 7:28 PM, lindaeliseruble <forums_noreply@adobe.com>