14 Replies Latest reply on Jul 11, 2014 12:54 AM by try67

    Doc Save As and Trusted Function

    creditunion123

      I have been reading over the forum and the adobe help files regarding this. I think I am close but since I need to get my IT department to assist in placing the js files where they have to go, I thought I might ask the forum if I am on the right track

       

      I still have to make sure the field values will not include an illegal characters. They wont be empty as the forms will be coming directly from our system -prefilled

       

      Currently these forms automatically email (although staff still have to hit the actual send button) when staff go to print the document.  The people who get these forms are just finding it a bit hard to keep up with the emails and have asked to just have the files save to a folder so they can look at when they have time

       

      This is what I have for my trust propagator function.  I assume this is the only js file I will need as it incoporates the trusted function?

       

      mySaveAs = app.trustPropagatorFunction(function(doc,path)
      {
        app.beginPriv();
         doc.saveAs(path);
        app.endPriv(); })

       

      myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
      {
        // Privileged and/or non-privileged code above

        app.beginPriv();
         mySaveAs(doc,path);
        app.endPriv();
        // Privileged and/or non-privileged code below });

       

      I got this code from the Adobe Help

       

      then I want to have this code in the Document Did Print area

       

      var name = this.getField("FormValues.accountNames_0").value
      var folio =this.getField("FormValues.folioNumber_0").value

      myTrustedSpecialTaskFunc(this, "/w/Public/AccountOpening/" + name + " " + folio,pdf);

       

      I have to read where to put the js file as I have seen some comments on the forum that where you place the js file has changed for those with Adobe X and Windows 7

       

      Would anyone be be able to let me know if I am on the right path before I get IT involved.  I suppose I could test the code on my own laptop to see if it would allow me to save the form.....

       

      Thank you

        • 1. Re: Doc Save As and Trusted Function
          George_Johnson MVP & Adobe Community Professional

          Read this: The Acrobat Ninja: Acrobat 10.1.1 JavaScript changes

           

          You have to manually create the folders that aren't present, and they must be named correctly.

           

          It's a good idea to use the valueAsString property instead of the value property to get the field values, since you're using the results as strings. It probably won't make a difference here, but it's a good habit to get into. You also have a typo in that last line of code. It should be:

           

          myTrustedSpecialTaskFunc(this, "/w/Public/AccountOpening/" + name + " " + folio + ".pdf");

           

          It would be a good idea to make sure those field value aren't blank if there's a chance that they could be.

           

          Also, consider using a try/catch block for the doc.saveAs call, and look at the return value so you can give the users a more helpful error message than what the default will be if something goes wrong.

           

          If you need help with any of this, post again.

          • 2. Re: Doc Save As and Trusted Function
            creditunion123 Level 1

            Thank you.

             

            I will look up using the valueAsString and how to do a try/catch.  Just learning javascript and pdf coding.  Fun though. ☺

             

             

            Linda Haworth

            Operations Services Manager

            • 3. Re: Doc Save As and Trusted Function
              creditunion123 Level 1

              not sure what I am missing

               

              I create the folder level script and placed in the C dirve - global not user.  I no longer get the security error I got before - so good

              My whole script though is

               

              mySaveAs = app.trustPropagatorFunction(function(doc,path)
              {
                app.beginPriv();
                 doc.saveAs(path);
                app.endPriv(); })

               

              myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
              {
                // Privileged and/or non-privileged code above

                app.beginPriv();
                 mySaveAs(doc,path);
                app.endPriv();
                // Privileged and/or non-privileged code below })

               

              I did not create two folder level scripts - one for the propagator and one for the actual function

               

              I then created a button on my form - to test the stuff with this code inside on mouse up

              var name = this.getField("FormValues.accountNames_0").value
              var folio =this.getField("FormValues.folioNumber_0").value

              myTrustedSpecialTaskFunc(this, "/w/Public/AccountOpening/" + name + " " + folio +".pdf");

               

              I now get an error saying myTrusted SpecialTaskFunc is not defined.

              how do I define this?

              • 4. Re: Doc Save As and Trusted Function
                George_Johnson MVP & Adobe Community Professional

                Make sure that you've closed Acrobat and restarted before trying to use that code.

                • 5. Re: Doc Save As and Trusted Function
                  creditunion123 Level 1

                  found an error when I cut and paste into the folder - am missing the last } at the end of the

                  myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
                  {
                    // Privileged and/or non-privileged code above

                    app.beginPriv();
                     mySaveAs(doc,path);
                    app.endPriv();
                    // Privileged and/or non-privileged code below })

                   

                  missing the } to close the function. Not sure if that would generate the error but will have to wait till tomorrow until IT can load the updated js file to my c drive as I do not have authority

                  • 6. Re: Doc Save As and Trusted Function
                    George_Johnson MVP & Adobe Community Professional

                    That should fix it.

                    • 7. Re: Doc Save As and Trusted Function
                      creditunion123 Level 1

                      It fixed that issue, but now when I hit my save button i get

                       

                      UnsupportedValueError: Value is unsupported. ===> Parameter cPath.

                      Doc.saveAs:4:Field Button1:Mouse Up

                       

                      Now my trusted function is on my cdrive.  I am trying to save to a network folder - under our W drive

                      hmm do I need the actual network name (we always just call it the W drive)

                       

                      drive.png

                      • 8. Re: Doc Save As and Trusted Function
                        creditunion123 Level 1

                        that did not work either

                        I changed the path to

                         

                        "/HO-VM-Saruman/WorkSpaces/Public/AccountOpening/" + name + " " + folio +".pdf");

                        and still got the same error message

                         

                        I added WorkSpaces as that is what IT says the full path is //HO-VM-SARUMAN/WorkSpaces/Public/AccountOpening
                        but I am still having the same cPath error

                        • 9. Re: Doc Save As and Trusted Function
                          George_Johnson MVP & Adobe Community Professional

                          As a test, try turning off Protect View in your security preferences: Edit > Preferences > Security (Enhanced)

                           

                          If it works, you won't want to leave it off, but instead set up the required whitelist, which requires a Windows registry edit.

                          • 10. Re: Doc Save As and Trusted Function
                            creditunion123 Level 1

                            Nope, it was already off

                             

                            Hmmm

                            I am at a loss

                             

                            Wonder if it has to do with set up

                            I am on a network

                            I saved the trusted function under my cdrive (on the network)  I am on a thin client

                             

                            The folder I want to save to is on the network

                            I will recheck my path – I have the slashes going the correct way (yes grasping at straws) as the actual path on the network you can see the slashes going the opposite way ( ok, my newbie status totally showing right now)

                            • 11. Re: Doc Save As and Trusted Function
                              George_Johnson MVP & Adobe Community Professional

                              To see what the path should look like, open a file that is in the same folder as the one you want to save to, open the JavaScript console by pressing Ctrl+J, and enter the following line of code:

                               

                              path

                               

                              With the cursor on that line, press Ctrl+Enter, or Enter on the numeric keypad. It will show the path of the current file, and that's what it should look like in your code, minus the file name at the end.

                              • 12. Re: Doc Save As and Trusted Function
                                creditunion123 Level 1

                                Yes, path looks correct

                                 

                                /HO-VM-SARUMAN/WorkSpaces/Public Folders/AccountOpening/test.pdf

                                 

                                Not sure why it is not working.  Perhaps I will try changing the code and try a hardcoded file name to save to and see what happens

                                 

                                Linda Haworth

                                • 13. Re: Doc Save As and Trusted Function
                                  creditunion123 Level 1

                                  Well that worked. Copied and Pasted the path from that code you showed me how to get (thank you) and then put a hardcoded name of mysavedoc.pdf – worked like a charm

                                  So I will play again with using a field to name the document

                                   

                                  Thank you so much for your help!!

                                   

                                  Linda

                                  • 14. Re: Doc Save As and Trusted Function
                                    try67 MVP & Adobe Community Professional

                                    The problem with using a field to name a file is that it can contain all kinds of illegal characters that can't be used in a file-name, or it can be empty... So you have to validate it properly, and maybe edit its value, before trying to use it in such a command.