6 Replies Latest reply on Aug 18, 2008 10:17 PM by John.Kordas

    JS Rename PDF using app.trustedFunction()

    John.Kordas Level 1
      I'm trying to create a simple rename Dialog that allows the user to rename the PDF and save it to a set folder location then close the doc.

      I'm getting this error in the console:

      this.saveAs is not a function
      4:App:Exec

      At the top of my script I have the trusted funtion:

      var JSRename = app.trustedFunction(function(myinfo)
      {
      app.beginPriv();
      this.saveAs("/c/hold/"+ myinfo +".pdf");
      this.closeDoc(true); // close the doc, no notification
      app.endPriv();
      });

      At the end of the Dialog code I call the trusted function:

      if("ok" == RenamePDF.DoDialog())
      {
      JSRename(RenamePDF.stredt1);
      //console.println("edt1:" + RenamePDF.stredt1);
      }

      At the bottom on the script I have the code to create a menu item that calles the Dialog:

      app.addToolButton({
      cName: "JSRename",
      cLabel: "JSRenamePDF",
      cEnable: "event.rc = (app.doc != null);",
      cExec: "MyRename();"});

      If I change my menu cExec to;

      cExec: "JSRename('test');"});

      My trusted function works fine. Is it possible to pass the value back from the Dialog tot he trusted fuction?
        • 1. Re: JS Rename PDF using app.trustedFunction()
          (Aandi_Inston) Level 1
          Look up the definition of "this" in the JavaScript reference. You must
          use "this" with extreme care, because its meaning changes.

          What you should probably do is pass the document you want to save as a
          parameter to the trusted function.

          However, I don't understand your statement "My trusted function works
          fine." Surely, it isn't?

          Aandi Inston
          • 2. Re: JS Rename PDF using app.trustedFunction()
            John.Kordas Level 1
            Hi Aandi,

            If I run:

            var JSRename = app.trustedFunction(function(myinfo)
            {
            app.beginPriv();
            this.saveAs("/c/hold/"+ myinfo +".pdf");
            this.closeDoc(true); // close the doc, no notification
            app.endPriv();
            });

            app.addToolButton({
            cName: "JSRename",
            cLabel: "JSRenamePDF",
            cEnable: "event.rc = (app.doc != null);",
            cExec: "JSRename('myTestDoc');"});

            A menu button will appear and when I click it the active PDF docuemnt will be saved to the C:\hold\ folder as myTestDoc.pdf.

            I will do some alerts to check id the data in the Dialog is being passed to the trusted function.
            • 3. Re: JS Rename PDF using app.trustedFunction()
              Patrick Leckey Level 3
              > If I run

              Where are you testing this, in the console? From a folder-level JavaScript, you may be better off using event.target to reference the currently active PDF.
              • 4. Re: JS Rename PDF using app.trustedFunction()
                John.Kordas Level 1
                I did my testing in the console and all was ok untill I saved my JS and tried to run it at folder-level. I'm now making changes to the script which is folder-level.

                before the line this.saveAs("/c/hold/"+ myinfo +".pdf");
                I tried app.alert(myinfo); and the alert worked. So the script does not know what the active(this) pdf is.

                Thanks PDL I'll look at event.target if I find a way to tell it select the active PDF then the script should work.
                • 5. Re: JS Rename PDF using app.trustedFunction()
                  John.Kordas Level 1
                  Thanks PDL,

                  event.target.saveAs("/c/hold/"+ myinfo +".pdf");

                  did the trick.

                  Now that it's working I've moved the destination to a server we have by using:

                  event.target.saveAs("/server_name/folder_on_server/"+ myinfo +".pdf");

                  This works fine on PC but Mac's don't like it. I've tried

                  \/\/\server_name/folder_on_server/

                  and

                  \\server_name\folder_on_server\

                  Any suggestions?
                  • 6. Re: JS Rename PDF using app.trustedFunction()
                    John.Kordas Level 1
                    I made a slight mistake in my previous post.

                    for the PC I use

                    event.target.saveAs("/server_name/share_name/folder_in_share/"+ myinfo +".pdf");

                    I found this works on the Mac

                    event.target.saveAs("/share_name/folder_in_share/"+ myinfo +".pdf");

                    Cheers.