Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have JavaScript select printer to use? [duplicate]

Possible Duplicate:
Printing to a specific printer from a web app

One of our intranet applications needs to print out to a non-default printer. Of course people regularly forget to select the correct printer.

I'm aware that you can not do this normally via JavaScript but given that the browser is IE9 and I can add the webapp to the trusted zone (and fiddle around with the security settings at will), is there any way to write JavaScript that will automatically select the correct printer? Perhaps using some ActiveX or other IE specific stuff.

like image 496
Kris Avatar asked Oct 25 '11 14:10

Kris


2 Answers

No, the Javascript object model includes a window.print() method that may activate the standard print dialogue of a Web browser, but that is as far as the functionality extends. It would not be appropriate or safe for Javascript code to be able to check the printers attached to a computer, look up printer properties or arbitrarily configure their settings.

I suggest to add a pop prior to printing where you remind the user to select the appropiate printer.

like image 93
isJustMe Avatar answered Nov 10 '22 14:11

isJustMe


If your browser is IE based you can use this activeX from meadroid:

http://www.meadroid.com/scriptx/index.asp

I have used it in the past and it permits to control the Printer attributes.

Here is an example from mmeadroid documentation:

<script>
function printWindow() {
  factory.printing.SetMarginMeasure(2); // set inches
  factory.printing.header = "This is MeadCo";
  factory.printing.footer = "Printing by ScriptX";
  factory.printing.portrait = false;
  factory.printing.leftMargin = 1.0;
  factory.printing.topMargin = 1.0;
  factory.printing.rightMargin = 1.0;
  factory.printing.bottomMargin = 1.0;
  factory.printing.copies = 1;
  factory.printing.printBackground = true;
  factory.printing.Print(false);
  factory.printing.WaitForSpoolingComplete();
  // navigate or close browser here //
}
</script>
like image 31
Matteo Conta Avatar answered Nov 10 '22 14:11

Matteo Conta