16 Replies Latest reply on Jul 5, 2011 7:57 AM by uklogistics

    Rename PDF and email with Adobe reader 9 script

    uklogistics Level 1

      Hello

       

      I want to be able to rename a PDF document in specific format, then provide user option to email PDF as attachment

       

      Problem is it does't work in Adobe Reader 9 , even with Enable menu items Javascript execution privileges

       

      It does work however with Adobe Acrobat Professional 8.

       

       

      The Debugger throws this error when executing in Adobe Reader 9


      RaiseError: This operation is not permitted.
      Doc.saveAs:16:Menu Send Document to FCL Client:Exec
      ===> This operation is not permitted.

       

      I understand that Adobe Reader cannot save any modifications to the the document content, however I not modifying content here, just renaming the document.

       

      in adobe reader there is an option for Save A Copy, is there a javascript equivalent to this command.

       

      or any other options to achieve this?

       

      thanks

       

      app.addMenuItem({
              cExec: "SendDoc();",
                    cParent: "Edit",
                   cName: "Send Document"
           });


      function SendDoc() {

      var dialogTitle = "Enter number";
      var defaultAnswer = "";
      var reply = app.response("Please enter 6digit number",
      dialogTitle, defaultAnswer);

      var myPath = "~~" + reply + "~~" + "Report_" + reply + ".pdf";
      this.saveAs(myPath);

       


      this.mailDoc(true, "edocuments@test.com", "cc test@test.com", "", myPath );

       

       


      return;

        • 1. Re: Rename PDF and email with Adobe reader 9 script
          try67 MVP & Adobe Community Professional

          saveAs must run in a trusted context. See the app.beginPriv and app.endPriv methods.

          Also, you must verify that the response entered by the client does not contain any illegal characters.

          I'm also not sure about the validity of your paths. Are you sure that using tilde's like that is correct?

          • 2. Re: Rename PDF and email with Adobe reader 9 script
            uklogistics Level 1

            Hi

             

            I used the app.beginPriv and app.endPriv methods methods, however Adobe reader 9.0 is throwing the same error;

             

            RaiseError: This operation is not permitted.
            Doc.saveAs:20:Menu Send Docs:Exec
            ===> This operation is not permitted.

            I do not get this error in Adobe Acrobat 8, however all the users do not have Acrobat, they use Adobe Reader 9

            Here is the JS code I used this time.

             

            Please help.

             

             

            app.addMenuItem({
                    cExec: "mySaveAs();",
                          cParent:"Edit",
                         cName: "Send Docs"
                 });
            
            var mySaveAs = app.trustedFunction(function(myDoc, myPath) {
            var dialogTitle = "Enter Number";
            var defaultAnswer = "";
            var reply = app.response("Please enter 6digit Client number e.g. 000001 for EX textiles",
            dialogTitle, defaultAnswer);
            
            var myPath = "~~" + reply + "~~" + "Report_" + reply + ".pdf"; 
            
            app.beginPriv();
            var myDoc = event.target;
            return retn = myDoc.saveAs(myPath); 
            app.endPriv();
            
            
            this.mailDoc(true, "edocuments@test.com", "cc test@test.com", "", myPath ); 
            
            
            
            return retn; 
            });  
            

             

            • 3. Re: Rename PDF and email with Adobe reader 9 script
              uklogistics Level 1

              Hello everyone, any ideas on this?


              Thanks

              • 4. Re: Rename PDF and email with Adobe reader 9 script
                try67 MVP & Adobe Community Professional

                There are many problems with your code:

                -The file is saved fine when I remove those tilde's and just use a regular

                path.

                -Be aware that you can't save the file to a non-existing folder.

                -The file will never be emailed because you're returning from the function

                before arriving to that line.

                -saveAs doesn't return a Doc object to the new file. You can continue using

                myDoc to refer to it after the saveAs command.

                • 5. Re: Rename PDF and email with Adobe reader 9 script
                  uklogistics Level 1

                  Hi

                   

                  Can you confirm if you got this working in Adobe Reader 9 ?

                   

                  Also, can I see the code you used?

                  Thanks

                  • 6. Re: Rename PDF and email with Adobe reader 9 script
                    try67 MVP & Adobe Community Professional

                    I got it to work in Reader X, so it should work in Reader 9 as well.

                    Here's the code I used:

                     

                    var mySaveAs = app.trustedFunction(function(myDoc, myPath) {
                    
                    var dialogTitle = "Enter Number";
                    
                    var defaultAnswer = "";
                    
                    var reply = app.response("Please enter 6digit Client number e.g. 000001 for EX textiles", dialogTitle, defaultAnswer);
                    
                    var myPath = "/c/temp/Report_" + reply + ".pdf";
                    
                    app.beginPriv();
                    
                    var myDoc = event.target;
                    
                    myDoc.saveAs(myPath);
                    myDoc.mailDoc(true, "edocuments@test.com", "test@test.com", "", myPath );
                    app.endPriv();
                    return myDoc;
                    });
                    

                    It is still missing things like validating the user input, but the main bit works.

                    Also, it's not clear to me why you're passing the doc reference and path as parameters and then overwrite them.

                    1 person found this helpful
                    • 7. Re: Rename PDF and email with Adobe reader 9 script
                      uklogistics Level 1

                      Added this to the top of your code

                       

                      app.addMenuItem({
                              cExec: "mySaveAs();",
                                    cParent: "Edit",
                                   cName: "Test"
                           });

                       

                      and tried to execute from the Edit drop down, however it is still throwing error. " This operation is not permitted "

                       

                       

                      Acrobat EScript Built-in Functions Version 9.0
                      Acrobat Annotations / Collaboration Built-in Functions Version 9.0
                      Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0
                      Acrobat SOAP 9.0

                      RaiseError: This operation is not permitted.
                      Doc.saveAs:21:Menu Test:Exec
                      ===> This operation is not permitted.

                       

                      I'm guessing there must be a setting in my Adobe Reader 9 that is causing this, if you are able to run the same script.

                       

                      FYG, the path c:\temp\ exists on the system i'm testing on,

                       

                      Any ideas?

                       

                      FYG, i'm a complete newbie to this javascript programming

                      • 8. Re: Rename PDF and email with Adobe reader 9 script
                        uklogistics Level 1

                        Hi

                         

                        I managed to get your code working using Adobe Reader X, however the email procedure is not attaching the file that has been renamed.

                         

                        The file that is being attached is the original file name, that is opened in the application.

                         

                        Is there anyway to attach the renamed file to the email, as this is the main purpose of the exercise?

                         

                        This special file naming convention is captured by a file scanner that routes the attachment to a job file, based on the number entered by the user.

                         

                        many Thanks

                        • 9. Re: Rename PDF and email with Adobe reader 9 script
                          try67 MVP & Adobe Community Professional

                          Yeah, I see what you mean... Try this:

                          Between the saveAs and mailDoc commands, add these lines:

                           

                          myDoc.closeDoc(true);
                          myDoc = app.openDoc(myPath);

                          • 10. Re: Rename PDF and email with Adobe reader 9 script
                            uklogistics Level 1

                            Hi

                             

                            It appears if the script  saves the document , closes it, opens it and send as attachment via email , our PDF document scanner cannot identify the PDF document as an attachment. using this code. mydoc.mailDoc(false, "edocs@test.com", "", "",mySubject);

                             

                            However if I send the email using this.mailDoc(false, "edocs@test.com", "", "",mySubject);  (i.e. not renaming the document etc) our document scanner picks up the PDF document.

                             

                             

                            It appears the Saveas method is somehow affecting / corrupting / encoding the document differently. The document is perfectly viewable.

                             

                            Any ideas what is going on here?

                             

                             

                             

                             

                             

                             

                            • 11. Re: Rename PDF and email with Adobe reader 9 script
                              try67 MVP & Adobe Community Professional

                              Since we don't know which document scanner you use, or how it works, it's not really possible to help you.

                              You might want to contact the manufacturers of the scanner regarding this.

                              • 12. Re: Rename PDF and email with Adobe reader 9 script
                                uklogistics Level 1

                                Hi

                                with the saveas function, it is possible to specify the encoding or are there any parameters that can be specified to keep the document as it is.

                                 

                                The reason for the saveas method in this scenerio is to bascially rename the document. nothing else needs to change.

                                • 13. Re: Rename PDF and email with Adobe reader 9 script
                                  try67 MVP & Adobe Community Professional

                                  Not really. You can specify a converter if you want to convert the file to

                                  another type, but that's it.

                                  Using saveAs is the same as using the built-in Save As command under the

                                  File menu. If that breaks your scanner, then you should try to solve the

                                  problem there.

                                  • 14. Re: Rename PDF and email with Adobe reader 9 script
                                    uklogistics Level 1

                                    Are there any other options for this script to send the document as an attachmnet , instead of using the default email client on PC (e.g. Outlook)?

                                     

                                    i.e. is it possible to define an SMTP server in the javascript and let adobe send the email?

                                     

                                    I think outlook is somehow modifing the email , so the document scanner cannot read it.

                                    • 15. Re: Rename PDF and email with Adobe reader 9 script
                                      try67 MVP & Adobe Community Professional

                                      No, but you can submit the file in other formats (XML, FDF, etc.)

                                      • 16. Re: Rename PDF and email with Adobe reader 9 script
                                        uklogistics Level 1

                                        Can it be submitted in TIFF or JPG?