This class simplifies the job of printing text on line printers, in C#. I had an application that needed to print on one of such printers, so I ended up writing this helper class. Basically, it's a wrapper for the spooler API (winspool.drv); the text to be printed is sent in "RAW" mode to the spooler so that no graphics printing is involved.
Using the Code
The use of the class is pretty easy. First, the desired printing device is selected by either writing the
PrinterName property or by calling the
LPrinter MyPrinter = new LPrinter();
MyPrinter.PrinterName = "Epson FX-80";
The actual printing is done like this:
MyPrinter.Open("Document Title Here");
ChoosePrinter() return a boolean, in case you want to check if the operation was successful.
Some basic text effects can be achieved by sending control codes to the printer, according to the following table:
|Code ||Description |
|14 ||enlarged characters on |
|20 ||enlarged characters off |
|15 ||compressed characters on |
|18 ||compressed characters off |
|ESC + "E" ||bold characters on |
|ESC + "F" ||bold characters off |
|12 ||FF (form feed) |
For more code, check the printer's manual.
Points of Interest
Unfortunately, there is no easy way to tell if an installed printer is a line printer or a graphical one (laser or inkjet), so I was not able to filter the print dialog of
ChoosePrinter(), making it display only line printers. This means that the user has to choose the right printer.
- 29-Sep-2008: First (and possibly only one) version