10 Replies Latest reply on Jan 22, 2014 11:56 AM by try67

    Print via PrintParams

    Netman

      Hello everybody. 

      I need to print first page into the file. I have trusted function:

      pPrint = app.trustedFunction( function(this,pp)

      {

      app.beginPriv();

      try

      {

      var pp = this.getPrintParams();

      pp.interactive = pp.constants.interactionLevel.silent;

      pp.firstPage = 0;

      pp.lastPage = 0;

      pp.fileName = "/c/temp/temp.pdf";

      pp.printerName = "Adobe PDF";

      this.print(pp);

      }

      catch(e)

      {

              app.alert("Error Trusted Function");

      }

      app.endPriv();

      }

      );

       

      and code for the button:

       

      if(typeof(pPrint) == "function")

      {

          var pp = this.getPrintParams();

          pp.interactive = pp.constants.interactionLevel.silent;

          pp.firstPage = 0;

          pp.lastPage = 0;

          pp.fileName = "/c/temp/temp.pdf";

          pp.printerName = "Adobe PDF";

          pPrint(pp);

      }

      else

      {

      app.alert("Error Button");

      }

       

      but it not work with error for buttons code:

       

      SyntaxError: missing formal parameter

      28:Folder-Level:App:Config.jsAcrobat EScript Built-in Functions Version 10.0

      Acrobat SOAP 10.0

       

      I just start to programming for Acrobat JavaScript not long ago and not  understand why buttons code not work.

      Would you be so kind to help me.

        • 1. Re: Print via PrintParams
          try67 MVP & Adobe Community Professional

          Your trusted function needs to only call the print command with the PrintParams parameter. That's it.

          It doesn't strike you as odd that you have the same code in both places?

          You need to pass to it a reference to the document object and the PrintParams object, which you're doing, but don't call it "this". That's a reserved keyword.

          So it should basically be:

           

          pPrint = app.trustedFunction( function(doc,pp) {

          app.beginPriv();

          try {

              doc.print(pp);

          }

          catch(e){

              app.alert("Error Trusted Function");

          }

          app.endPriv();

          }

          );

           

          And you call it like this:

          pPrint(this, pp);

          • 2. Re: Print via PrintParams
            Netman Level 1

            Thanks for the quick reply. Now better understood. I've tried a lot of variants, but all the stops at

            var pp = get.PrintParems();

            with SyntaxError: invalid object initializer 64:Folder-Level:App:Config......

            I can not understand why does not work the button code. I would be very grateful if you help to understand.

            • 3. Re: Print via PrintParams
              try67 MVP & Adobe Community Professional

              I'm now noticing that the error message talks about Config.js, which is am internal JS file of Acrobat... Did you mess around with it in any way? If that file is corrupt then you have a serious problem and should probably run a Repair Installation on the application.

              • 4. Re: Print via PrintParams
                Test Screen Name Most Valuable Participant

                Don't use "this" in a function.

                Don't use just "getPrintParams" either. You need to correctly refer to the object that owns it.

                • 5. Re: Print via PrintParams
                  Netman Level 1

                  Config.js is my file with declared trusted functions and other function work correct (when not use this part of code).

                  • 6. Re: Print via PrintParams
                    try67 MVP & Adobe Community Professional

                    Ah, OK, guess I mistook it withsomething else. At any rate, you have an error in this line:

                    var pp = get.PrintParems();

                     

                    This is not how you access the PrintParams object, and you shouldn't do that in the trusted function, anyway.

                    • 7. Re: Print via PrintParams
                      Netman Level 1

                      okay. I just ran the code on Mac and debugger wrote that the error in the file with trusted functions.

                      in this case, I tried to save a document through a trusted function.

                       

                      Acrobat JavaScript Debugger Functions Version 10.0

                      Acrobat EScript Built-in Functions Version 10.0

                      Acrobat SOAP 10.0

                      doc.saveAs is not a function

                      7: Field: Mouse Up

                      • 8. Re: Print via PrintParams
                        try67 MVP & Adobe Community Professional

                        You need to provide the full code. We can't help you with just fragments...

                        • 9. Re: Print via PrintParams
                          Netman Level 1

                          On pdf page I have two buttons "Print" and "Save"

                          Trusted function code in file Config.js is

                          //For Save

                          mySaveAs = app.trustedFunction(function(doc,cPath)

                          {

                          app.beginPriv();

                          try

                          {

                          doc.saveAs(cPath);

                          }

                          catch(e)

                          {

                          app.alert("Error Config");

                          }

                          app.endPriv();

                          }

                          );

                          //For Print

                          pPrint = app.trustedFunction( function(doc,pp) {

                          app.beginPriv();

                          try {

                              doc.print(pp);

                          }

                          catch(e){

                              app.alert("Error Trusted Function");

                          }

                          app.endPriv();

                          }

                          );

                           

                          and save button on pdf page has code

                           

                          if(typeof(mySaveAs) == "function")

                          {

                          mySaveAs({

                          cPath: "/c/temp/temp.pdf"

                          });

                          }

                          else

                          {

                          app.alert("Missing Save Fucntion " + "Please contact forms administrator");

                          }

                          for print button:

                           

                          if(typeof(pPrint) == "function")

                          {

                          var pp = this.getPrintParams();

                          pp.interactive = pp.constants.interactionLevel.automatic;

                          pp.firstPage = 0;

                          pp.lastPage = 0;

                          pp.fileName = "/c/temp/temp.pdf";

                          pp.printerName = "Adobe PDF";

                          pPrint(this, pp);

                          }

                          else

                          {

                          app.alert("Missing Print Fucntion " + "Please contact forms administrator");

                          }

                          • 10. Re: Print via PrintParams
                            try67 MVP & Adobe Community Professional

                            That's better...

                             

                            You're not called mySaveAs correctly. You should call it like this:

                             

                            mySaveAs(this, "/c/temp/temp.pdf");

                            1 person found this helpful