Click here to Skip to main content
Licence Public Domain
First Posted 26 Sep 2008
Views 48,756
Downloads 1,094
Bookmarked 48 times

Line Printer Class in C#

By Antonino Porcino | 26 Sep 2008
A simple C# class for printing on old dot matrix line printers.
2 votes, 8.7%
1

2

3
7 votes, 30.4%
4
14 votes, 60.9%
5
4.65/5 - 23 votes
2 removed
μ 4.30, σa 2.05 [?]

Introduction

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 ChoosePrinter() method:

LPrinter MyPrinter = new LPrinter(); // creates the printer object
MyPrinter.ChoosePrinter();// let user choose the printer device

// alternatively:
MyPrinter.PrinterName = "Epson FX-80";
// uses a specific named printer

The actual printing is done like this:

MyPrinter.Open("Document Title Here"); // opens and tells the spooler the document title
MyPrinter.Print("Some text....\r\n");  // actual printing (CR+LFs are neeeded)
MyPrinter.Print("\x0C");               // sends a form feed (ejects the paper)
MyPrinter.Close();                     // Close the spooler

All methods Open(), Print(), Close(), and 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 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.

History

  • 29-Sep-2008: first (and possibly only one) version.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

Antonino Porcino

Software Developer

Italy Italy

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberwkiess0116:37 15 Jan '12  
QuestionMake gujrati print in C# PinmemberCHAVADA SURAJ16:03 12 Dec '11  
AnswerRe: Make gujrati print in C# PinmemberAntonino Porcino22:36 12 Dec '11  
AnswerRe: Make gujrati print in C# Pinmemberlukac1:39 23 Dec '11  
QuestionLine Printer Class problem PinmemberZil-e-Huma2:03 16 Aug '11  
AnswerRe: Line Printer Class problem PinmemberAntonino Porcino4:55 16 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma18:50 16 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma20:42 16 Aug '11  
GeneralRe: Line Printer Class problem PinmemberAntonino Porcino21:57 16 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma1:06 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberAntonino Porcino2:50 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma5:56 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberAntonino Porcino6:32 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma19:18 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberAntonino Porcino23:26 17 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma0:04 18 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma0:32 18 Aug '11  
GeneralRe: Line Printer Class problem PinmemberAntonino Porcino1:09 18 Aug '11  
GeneralRe: Line Printer Class problem PinmemberZil-e-Huma23:13 17 Aug '11  
Questionprint image ? PinmemberYusufHermanto6:06 6 Aug '11  
GeneralPrint UniCode characters and other font size Pinmemberunodei20:58 24 Sep '10  
GeneralRe: Print UniCode characters and other font size PinmemberAntonino Porcino0:45 25 Sep '10  
GeneralRe: Print UniCode characters and other font size Pinmemberunodei3:32 25 Sep '10  
GeneralRe: Print UniCode characters and other font size PinmemberAntonino Porcino8:18 25 Sep '10  
GeneralRe: Print UniCode characters and other font size Pinmemberunodei15:31 26 Sep '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 26 Sep 2008
Article Copyright 2008 by Antonino Porcino
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid