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.ChoosePrinter();
MyPrinter.PrinterName = "Epson FX-80";
The actual printing is done like this:
MyPrinter.Open("Document Title Here"); MyPrinter.Print("Some text....\r\n"); MyPrinter.Print("\x0C"); MyPrinter.Close();
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:
||enlarged characters on
||enlarged characters off
||compressed characters on
||compressed characters off
|ESC + "E"
||bold characters on
|ESC + "F"
||bold characters off
||FF (form feed)
For more codes, 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.