Printing labels

Printing labels

Postby Rick Lipkin » Tue Oct 25, 2011 12:51 pm

To All

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)
 
User avatar
Rick Lipkin
 
Posts: 2664
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Printing labels

Postby James Bott » Tue Oct 25, 2011 1:52 pm

Rick,

It seems you are calculating nRow and nCol by correcting them with constant pixels (30,40, or 50 pixels). You must use distance (mm, inches) instead of pixels since distance is universal but pixels is dependent on the printer's resolution.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Printing labels

Postby Rick Lipkin » Tue Oct 25, 2011 2:49 pm

James

I am in total agreement with you .. I did something like that for another program .. if I recall taking the horiz resolution * .xxx number to get the co-ordinates ..

I was trying to avoid that .. unfortunately I know you are correct.

RIck
User avatar
Rick Lipkin
 
Posts: 2664
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 48 guests