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

DATATypeDescription
cPortCharacterPrinter port name, default "LPT1"
hDCHandleWindows printer device context handle
nRow / nColNumericCurrent cursor row and column position
lAnsiToOemLogicalConvert ANSI text to OEM character set
nLPPNumericLines per page (page length)
bNewPageCode blockCode block executed at the start of each new page
bPageChangeCode blockCode block executed when a page ends

Methods

MethodDescription
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

See Also