TDosPrn
Source: source/classes/tdosprn.prg
Standalone class
TDosPrn emulates DOS-style character-mode printing to a Windows printer or file. It provides row/column positioning, page control, and escape-sequence commands, making it suitable for generating plain-text invoices, reports, and labels on dot-matrix or line printers.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cPort | Character | Printer port name, default "LPT1" |
hDC | Handle | Windows printer device context handle |
nRow / nCol | Numeric | Current cursor row and column position |
lAnsiToOem | Logical | Convert ANSI text to OEM character set |
nLPP | Numeric | Lines per page (page length) |
bNewPage | Code block | Code block executed at the start of each new page |
bPageChange | Code block | Code block executed when a page ends |
Methods
| Method | Description |
|---|---|
New( cPort, lFile, lLaser, nLPP, bNewPage ) | Open a printer or file with lines-per-page and new-page callback |
StartPage() / EndPage() | Begin and end a printed page |
Say( nRow, nCol, cText ) | Print text at the specified row and column |
SayNow() | Print text at the current cursor position |
SayCmp() | Print a formatted, compressed line |
Command( cStr, ... ) | Send an escape/printer command sequence |
Write( cText ) | Write raw text to the printer |
PrintFile( cFile ) | Send the content of a file to the printer |
Example: Dot Matrix Invoice
#include "FiveWin.ch"
function Main()
local oPrn
oPrn := TDosPrn():New( "LPT1", .F., .F., 66 )
oPrn:StartPage()
oPrn:Say( 1, 10, "INVOICE #1024" )
oPrn:Say( 3, 5, "Customer: John Doe" )
oPrn:Say( 5, 5, "Item" )
oPrn:Say( 5, 40, "Qty" )
oPrn:Say( 5, 50, "Price" )
oPrn:Say( 7, 5, "Widget A" )
oPrn:Say( 7, 40, "2" )
oPrn:Say( 7, 50, "19.95" )
oPrn:EndPage()
oPrn:StartPage()
oPrn:Say( 1, 5, "Page 2 - Continued" )
oPrn:EndPage()
return nil
Notes
- When
lFileis.T., output is written to a file instead of the physical printer. - The
lLaserflag adjusts page handling for laser printers that require form-feed characters. - Set
lAnsiToOemto.T.for proper character display on older dot-matrix printers using the OEM character set. - The
bNewPagecode block is a convenient place to print page headers or column titles. - Use
Command()to send printer-specific escape sequences (e.g., condensed print, bold on/off).