Silent Print in Acrobat Using JavaScript

I received a question from a customer on whether or not it is possible to create a toolbar button that will perform a silent print in Acrobat.  Well, it turns out that using JavaScript it is possible and really isn’t all that difficult.

Here’s some code:

    
    // if the application is Adobe Acrobat...
    //then create the silent print button
    if(app.viewerType == "Exchange-Pro") {

        app.trustedFunction(customSilentPrint);

        app.addToolButton({
            cName: "customSilentPrint",
            cExec: "customSilentPrint()",
            cTooltext: "Print Silent",
            cLabel: "Print Silent",
            cEnable: "event.rc = (app.doc != null)" });
        }

    function customSilentPrint(){

        // explicitly raise privileges
        app.beginPriv();

        try{
            // get the printer params
            var pp = this.getPrintParams();

            // don't show the print dialog window
            pp.interactive = pp.constants.interactionLevel.silent;
        }
        catch(err){
            app.alert("Error setting up printing parameters.\n\n" + err);
        }

        try{
            this.print(pp);
        }
        catch(err){
            app.alert("Error Printing.\n\n" + err);
        }

        // end explicit privileges
        app.endPriv();
    }



As you can see, there really isn’t much to this code, but let’s break it down.

First we check to ensure we are in Acrobat and, if so, we add the button called “Print Silent” to the Acrobat toolbar:

    // if the application is Adobe Acrobat...then create the silent print button
    if(app.viewerType == "Exchange-Pro") {

        app.trustedFunction(customSilentPrint);

        app.addToolButton({
            cName: "customSilentPrint",
            cExec: "customSilentPrint()",
            cTooltext: "Print Silent",
            cLabel: "Print Silent",
            cEnable: "event.rc = (app.doc != null)" });
    }


Next we create the function called customSilentPrint and raise privileges:

    function customSilentPrint(){

        // explicitly raise privileges
        app.beginPriv();


Within the function we get to the meat of the work by creating a print params object and setting the interactionLevel to silent.

        try{
            // get the printer params
            var pp = this.getPrintParams();
        
            // don't show the print dialog window
            pp.interactive = pp.constants.interactionLevel.silent;
        }


Now that we are set up to print silent, call the print function with these lines:

        try{
            this.print(pp);
        }
        catch(err){
            app.alert("Error Printing.\n\n" + err);
        }


To finish off our code we lower our privileges and close out the function:

        // end explicit privileges
        app.endPriv();

    }


As you can see there’s really no magic here, but this JavaScript code is a nifty little way to print silently in Acrobat.

Also, I haven’t researched silent printing using reader, but if you have tried it and succeeded or failed, please feel free to add to the post via comments.

BTW – If you don’t know how to create a toolbar button or install JavaScript in Acrobat, check out my collegue Venkata’s post here.