Before we explore the challenges of Terminal Server printing and the many solutions, you need to understand how Windows printing works. After all, the actual process by which a Terminal Server prints is no different than any other Windows computer.
When you look under the hood, there are a surprising number of steps that take place whenever a document is printed. We could write an entire book detailing the exact printing process that takes place, but to be able to successfully design Terminal Server environments, you just need to know the basics.
The printing process varies slightly depending on whether you're printing to a local printer or a network printer, but the same basic steps take place in each case. Behind the scenes, there are three phases that take place from the moment you hit the "print" button in your application to the moment the finished print job appears on the printer:
Phase 1. Windows Application.
Phase 2. Print Spooler.
Phase 3. Printer (or "Print Device" as Microsoft calls it).
Figure 8.1: The Windows printing process
Phase 1. Windows Application
When a user requests a printout from a Windows application, the application is responsible for generating its own output in preparation for printing. This output includes items such as formatting the pages properly and adding page numbers. The application processes its printer output via a Windows subsystem called the Graphics Device Interface (GDI). The GDI generates the application's output in the form of a metafile that contains data and instructions for the printer. (This metafile is usually referred to as "print data.")
The preferred format of this print data is Microsoft's own enhanced metafile (EMF format). EMF print data is preferred over RAW format because EMF processing is less processor-intensive and it allows for background printing.
EMF files are not printer-specific. An application would generate the same EMF file for a printout no matter what kind of printer it was printing to. The file is the common middleman between the application and the printer driver. In order to understand this, let's consider how the following line of text would be printed:
All people seem to need data processing.
The EMF file for this line of text would contain instructions for the printout, including things like the color, font, characters, and the spacing. The EMF file is a vector-based document that is very small in size.
Once the GDI has written the EMF file to disk, the print data is passed into the Windows print subsystem.
Phase 2. Print Subsystem
The Windows print subsystem performs many printing-related functions. The easiest way to understand what it does is to break it up into logical steps. This subsystem is responsible for several tasks:
Receiving the EMF file from the GDI.
Determining whether the target printer is a local printer or a network printer.
Using the print driver to translate the EMF file into the printer's raw format. (At this point the "print data" becomes a "print job.")
Temporarily holding the print job if the printer is offline or otherwise unavailable.
Ensuring that the print job is successfully transferred to the printer.
The exact process that takes place depends upon the type of printer that the print job is being sent to. A printing component called the "print router" sends print data down separate paths depending on whether the printer is a network or local printer.
For remote printing, the unprocessed EMF file that was received from the GDI is sent to the print server to be rendered with the proper print driver.
On the other hand, if the print job is destined for a local printer, the local print spooler uses the print drivers to translate the EMF file into the printer's raw data format. This time-consuming and processor-intensive process is called "rendering." The rendered print job contains the raw data (print job) that is specific to the printer. Take another look at our example:
All people seem to need data processing.
In this case, the rendered print job would contain the printer-specific detailed instructions and formatting needed for printing in the printer's native language.
This would include resolution, paper tray information, form feed data, and the rasterized image of the page. Rendered print jobs vary in size depending on the type of printer and how well the drivers are written. In most cases, however, the rendered print job files are much larger than the EMF print data files.
Once the print job is created, the print spooler ensures that the file is transferred to the printer.
Phase 3. Printer
In the final printing phase, the printer receives the rendered print job from the print spooler. The printer prints this file regardless of its format. This is why printers will print garbage if the wrong drivers are used. Using the wrong drivers creates print jobs that are not compatible with the printer. However, the printer doesn't know this and it tries to print whatever it receives.