سؤال

I have a PDF file with some scripting inside. The scripts are allowed to change the printer to which the document is being printed (because we have dedicated printer for barcodes and other printer for regular documents). The problem is, I have no idea how to reset the printer to the computer's default one.

The printing code is as following:

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), the getPrintParams() returns default print parameters and pp.printerName set to '' (empty string) means default printer. I realized that none of that is true. Actually getPrintParams() returns last used parameters (not a new/default one) and pp.printerName = '' does not reset printer to the default one, instead it uses last chosen printer.

Moreover the PrintParams object seems to be shared across different opened documents, so I cannot store the name of default printer (read from first call of getPrintParams()) in some variable, because actually I don't know if the read value refers to the default printer or it was already changed by other opened documents.

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

Please help, how to reset programmatically the printer to the default one?

هل كانت مفيدة؟

المحلول

Actually the problem can be worked around using the global object, which is shared across multiple opened documents in one instance of adobe reader.

First time, the document is loaded, I check whether global object contains (my own) property defaultPrinter, unless that I call getPrintParams(), read the printerName field and assign it to the global.defaultPrinter. Then I can just read the field to obtain the default's printer name. The code is as follwing:

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

نصائح أخرى

Setting pp.printerName = '##NameOfAPrinterThatDoesntExists##' will reset the default printer. Take it easy.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top