TPrinter is FiveWin's printer device context class. It wraps the Windows GDI printing API,
providing methods for text output, lines, boxes, bitmaps, barcodes, charts, and more. TPrinter
supports multiple coordinate systems (pixels, centimeters, millimeters, inches), print preview
with metafile recording, and PDF output via multiple engines (I2PDF, HaruPDF, FWPDF).
Key DATA Members
DATA
Type
Description
hDC
Numeric
Printer device context handle
hDCOut
Numeric
Output DC (may be metafile DC for preview)
oFont
TFont
Current font object
cDocument
Character
Document/job name
cModel
Character
Printer model name
cFile
Character
Output file (for PDF)
nPage
Numeric
Current page number
nXOffset
Numeric
X offset for output
nYOffset
Numeric
Y offset for output
nPad
Numeric
Text padding mode (PAD_LEFT, PAD_RIGHT, PAD_CENTER)
#include "FiveWin.ch"
function Main()
local oPrn, oFont
PRINT oPrn NAME "CM Report" PREVIEW
DEFINE FONT oFont NAME "Calibri" SIZE 0, -12 OF oPrn
PAGE
// Using centimeters (easier for layout)
oPrn:CmSay( 1.0, 1.0, "Report Title", oFont )
oPrn:CmLine( 1.5, 1.0, 1.5, 18.0 )
oPrn:CmBox( 2.0, 1.0, 5.0, 18.0 )
oPrn:CmSay( 2.5, 1.5, "This text is at 2.5cm down, 1.5cm from left", oFont )
oPrn:CmSay( 3.0, 1.5, "Page size: " + ;
LTrim( Str( oPrn:CmHorzPhySize() ) ) + " x " + ;
LTrim( Str( oPrn:CmVertPhySize() ) ) + " cm", oFont )
ENDPAGE
ENDPRINT
oFont:End()
return nil
Example: Graphics and Images
#include "FiveWin.ch"
function Main()
local oPrn, oFont, oPen
PRINT oPrn NAME "Graphics Demo" PREVIEW
DEFINE FONT oFont NAME "Arial" SIZE 0, -16 OF oPrn
DEFINE PEN oPen WIDTH 3
PAGE
// Boxes
oPrn:Box( 100, 100, 400, 600, oPen )
oPrn:RoundBox( 100, 700, 400, 1200, 30, 30, oPen )
// Ellipse
oPrn:Ellipse( 500, 100, 800, 600 )
// Image
oPrn:PrintImage( 500, 700, "logo.png", 500, 300, .T. )
// Barcode
oPrn:PrintBarcode( "1234567890", 900, 100, 600, 200, , "EAN13" )
// Pie chart
oPrn:PieChart( { 1200, 100, 1800, 700 }, ;
{ 30, 45, 25 }, ;
{ CLR_RED, CLR_GREEN, CLR_BLUE } )
ENDPAGE
ENDPRINT
oFont:End()
oPen:End()
return nil
Example: Direct PDF Output
#include "FiveWin.ch"
function Main()
local oPrn, oFont
// Output directly to PDF file
PRINT oPrn NAME "My Document" FILE "output.pdf"
DEFINE FONT oFont NAME "Arial" SIZE 0, -14 OF oPrn
PAGE
oPrn:Say( 100, 100, "This goes directly to PDF", oFont )
ENDPAGE
ENDPRINT
oFont:End()
// Open the PDF
ShellExecute( 0, "open", "output.pdf" )
return nil
Coordinate System Methods
Method
Description
Cmtr2Pix( @nRow, @nCol )
Convert centimeters to pixels (by reference)
Mmtr2Pix( @nRow, @nCol )
Convert millimeters to pixels
Inch2Pix( @nRow, @nCol )
Convert inches to pixels
Pix2Cmtr( nRow, nCol )
Convert pixels to centimeters
Pix2Mmtr( nRow, nCol )
Convert pixels to millimeters
Pix2Inch( nRow, nCol )
Convert pixels to inches
PDF Delegation Architecture
TPrinter supports transparent PDF output through a call-log recording and replay
mechanism. When one of the PDF-related class data flags (listed above) is enabled,
every drawing command is captured as a call-log entry and replayed through the
selected PDF backend at page completion. The application code does not change at
all — the same TPrinter:Say(), TPrinter:Line(),
and other drawing calls produce PDF output without any code modifications.
The delegation architecture works as follows:
The aCallLog array stores every drawing operation performed on the printer device context.
AddLog() records each individual call — Say, Line, Box, Ellipse, PrintImage, etc. — along with its parameters.
When a PDF flag is active, AddLog() captures each call during the page and EndPage() replays the accumulated entries through the selected PDF backend.
The same mechanism works for print preview: the metafile recording (lMeta) captures GDI calls for on-screen rendering, while the PDF flags capture the same logical operations for file output.
This design ensures that any application using standard TPrinter drawing commands
can produce PDF output simply by setting one class data flag at the start of the
print job, with no changes to the drawing logic itself.