1. Home
  2. Computing & Technology
  3. JavaScript

Print Directly to Printer
Which Printer should Javascript print on?

By , About.com Guide

One query that turns up a lot in the various Javascript forums asks how to send the page directly to the printer without first displaying the print dialog box.

Rather than just telling you that it can't be done I thoght that an explanation of why such an option is not possible would be more useful.

Which print dialog box displays when someone presses the print button in their browser or the Javascript window.print() method runs depends on the operating system and what printers are installed on the computer.

As most people run Windows on their computer, I will describe how the printing setup works on that operating system. The *nix and Mac operating systems differ slightly in the details but verall are set up similar.

There are two parts to the print dialog box on Windows. The first of these is part of the Windows API (Application Programming Interface). The API is a set of common code pieces that are held in the various DLL (Dynamic Link Library) files that are part of the Windows operating system. Any Windows program can (and should) call the API to perform common functions such as displaying the Print Dialog box so that it will work the same way in all programs and not have different options in different places the way the print option did back in DOS program days. The Print Dialog API also provides a common interface allowing all programs access to the same set of printer drivers rather than printer manufacturers having to create driver software for their printer for each individual program that wanted to use it.

The printer drivers are the other half of the print dialog. There are several different languages that different printers understand that they use to control how the page prints (eg. PCL5 and Postscript). The printer driver instructs the Print API as to how to translate the standard internal print format that the operating system understands into the custom markup language that the specific printer understands. It also adjusts the options that the Print dialog displays to reflect the options offered by the specific printer.

An individual computer may have no printers installed, it may have one local printer, it may have access to several printers over a network, it may even be set up to print to PDF or preformatted print file. Where more than one "printer" is defined one of them is designated the default printer which means that it is the one that displays its details in the print dialog when it first appears.

The operating system keeps track of the default printer and identifies that printer to the various programs on the computer. This allows the programs to pass an extra parameter to the print API telling it to print directly to the default printer without displaying the print dialog first. Many programs have two different print options - a menu entry that displays the print dialog and a toolbar fast print button that sends direct to the default printer.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Controls and Widgets
  5. Events
  6. Print Directly to Printer Not Possible With JavaScript>

©2009 About.com, a part of The New York Times Company.

All rights reserved.