Reset default printer in Adobe Reader JavaScript API

I have a PDF file with some scripts inside. Scripts can change the printer the document is printed to (because we have a dedicated printer for barcodes and another printer for regular documents). The problem is, I have no idea how to reset the printer to the default computer.

The print code looks like this:

var pp = getPrintParams(); // get printing parameters
pp.interactive = pp.constants.interactionLevel.automatic; // do not prompt user
pp.printerName = 'barcode_printer'; // set printer name
this.print(pp); // print

      

According to the JavaScript API Reference (pages 314, 583), getPrintParams()

returns the default print settings and is pp.printerName

set to ''

(empty string) means the default printer. I realized that all this is not true. It actually getPrintParams()

returns the last used settings (not new / default), pp.printerName = ''

not the printer reset, but uses the last selected printer.

Also, the object PrintParams

appears to be shared between different open documents, so I can't store the default printer name (read from the first call getPrintParams()

) in some variable, because I don't actually know if the read value refers to the default printer or has already been modified by other open documents.

The behavior is compatible across different versions of Adobe Reader (9, 10, 11) and Foxit Reader.

Please help how to reset programmatically to use the default printer?

+3


source to share


2 answers


In fact, the problem can be solved by using an object global

that is shared by multiple open documents in a single instance of Adobe Reader.

The first time the document is loaded, I check if the global

object (my own) contains a property defaultPrinter

, unless I call getPrintParams()

, read the field printerName

and assign it.Then global.defaultPrinter

I can just read the field to get the default printer name. The code looks like this:



if (global.defaultPrinter === undefined) {
    global.defaultPrinter = getPrintParams().printerName;
}

      

+1


source


The setting pp.printerName = '##NameOfAPrinterThatDoesntExists##'

will be reset to the default printer. Take it easy.



0


source







All Articles