I am struggling with the Label sample with getting the same ( or reasonable ) results with multiple printers. I am using standard 3 across and 10 labels down 1 x 2 5/8 30 per page.
I realize that each printer has its own characteristics and the label example tries to use the printers pixel horizontal and vertical resolution ..
It seems that my labels 'creep' up and down the page not so much across .. I have compensated ( as in the sample ) with +- to the Height and width .. and there seems to be the problem .. side margins are not the problem .. but it is the manual adjustments to the Height and width that seem to be the variable factor in multiple printers.
I would appreciate any advice or pixel calculation that would achieve the same or similar results from multiple printers ( compile code below and try on multiple printers ) .. or if someone has any 3rd party Label classes they would like to share I would be most grateful.
Rick Lipkin
- Code: Select all Expand view
//-- dpolabl.prg
STATIC oDLG,mVIEW,oSAY,oCBX1,cITEM1,cSELECT,LABLDBF
#INCLUDE "FIVEWIN.CH"
//----------------------
func _dpolabl()
SET DELETED on
REQUEST DBFCDX
rddsetdefault ( "DBFCDX" )
mVIEW := "V"
LABLDBF := " "
DEFINE DIALOG oDlg ;
FROM 5, 8 to 21, 48 ;
TITLE "DPO Label Generation" ;
STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME,WS_CAPTION )
@ 2,2 SAY "Labels for" of oDlg
@ 4,2 SAY "Print or View (P/V)" of oDlg
@ 4,13 GET mVIEW of oDlg pict "@!" valid mVIEW $ 'PV'
@ 6,5 BUTTON "&Run" ;
SIZE 25,10 of oDLG ;
ACTION labl()
@ 6,15 BUTTON "&Quit" ;
SIZE 25,10 of oDLG ;
ACTION ( dbCloseAll(), ;
oDlg:End() )
ACTIVATE DIALOG oDlg
CLOSE DATABASES
RETURN( NIL )
//----------------------
static FUNC LABL()
LOCAL oPrinter, oFont,n,m,nMOD,nTCOL
LOCAL nWidth ,; // label Width
nHeight ,; // label height
nMargin // Printing margin (.2 inches)
LOCAL nCounter ,; // counter of lbl on each page
nRow ,; // current row
nCol ,; // current col
nOldRow // old row position
IF mVIEW = "V"
PRINTER oPRINTER FROM USER ;
PREVIEW MODAL ;
NAME "DPO Labels"
ELSE
PRINTER oPRINTER from USER ;
NAME "DPO Labels"
IF EMPTY( oPRINTER:hDC )
CLOSE DATABASES
MsgStop ( "Printer not Ready !" )
oDlg:END()
RETURN(NIL)
ENDIF
ENDIF
USE CUSTOMER // from samples folder
GO TOP
IF EOF()
CLOSE DATABASES
CursorArrow()
MsgStop( "Sorry ... No records to Print" )
oDlg:END()
RETURN(NIL)
ENDIF
* DEFINE FONT oFont NAME "Courier" SIZE 10, 16 of oPRINTER
* DEFINE FONT oFont FROM USER OF oPrinter
DEFINE FONT oFont NAME "Courier New" SIZE 0,-10 BOLD of oPRINTER // SIZE 10 -40
nLblWid := 3
nLblHei := 10
nWidth = oPrinter:nHorzRes() / nLBLWID // shorten length by
nHeight = oPrinter:nVertRes() / nLBLHEI // half a label
nMargin = Int( oPrinter:nLogPixelX() * 0.4 )
nCOUNTER := 0
nTCOL := 0
CursorWait()
DO WHILE .not. EOF()
IF nCOUNTER == 0
nRow := nMARGIN // top margin
nCol := Int( oPrinter:nLogPixelX() * 0.00 ) // side margin ( mod here )
oPrinter:StartPage()
ENDIF
nOLDROW := nROW
// creep here based on the number adj and not a pixel calc
oPRINTER:Box( nROW, nCOL, (nOLDROW + (nHEIGHT -60)), (nCOL + (nWIDTH -70)) )
oPRINTER:SAY( nROW+50 , nCOL+30, ;
Trim( CUSTOMER->First ) + " " + CUSTOMER->Last, oFont )
nROW += oFONT:nHEIGHT
oPRINTER:SAY( nROW+50 , nCOL+30, CUSTOMER->Street, oFont )
nROW += oFONT:nHEIGHT
oPRINTER:SAY( nROW+50 , nCOL+30, ALLTRIM(CUSTOMER->CITY)+" "+;
CUSTOMER->STATE+" "+CUSTOMER->ZIP, oFont )
nROW := (nOLDROW + (nHEIGHT-40))
SELECT CUSTOMER
SKIP
nTCOL++
IF nTCOL = nLBLHEI
nTCOL = 0
nROW := nMARGIN
nCOL += nWIDTH+30 // horz space between labels ( mod here )
ENDIF
nCOUNTER++
IF nCOUNTER == (nLBLHEI * nLBLWID) .and. .not. CUSTOMER->(EOF())
nCOUNTER := 0
oPRINTER:EndPage()
ENDIF
ENDDO
CursorArrow()
oPrinter:EndPage()
IF mVIEW = 'V'
oPRINTER:Preview()
ELSE
PrintEnd()
ENDIF
RELEASE FONT oFont
CLOSE DATABASES
oDLG:End()
RETURN(NIL)