I found myself needing to print labels recently (the Avery self-adhesive type, 65 per page) but the HELP isn’t very helpful. I have battled with this task in the past without success but the solution is oh-so-simple, I hope it helps someone else.
There are two golden nuggets in the HELP to note:
- Delete all report sections, except the Detail
- Set Detail height and width to the label size
I move the DETAIL around the page positioning it for each of 65 labels in turn then issue a Print(RPT:Detail)
I resize the DETAIL as well, so point 2 above isn’t fixed in stone.
The code sample below uses my own data queue “Q”, you’ll need to provide your own.
PrintLabels PROCEDURE
i LONG
dwTopMargin LONG(480) ! my laser & inkjet printers need a different top margin
dwLeftMargin LONG(197) ! my laser & inkjet printers need a different left hand margin
dwLabelWidth LONG(1500) ! Avery Label = 38.1mm wide => 1500 thous inch
dwLabelHeight LONG(835) ! Avery Label = 21.2mm tall => 835 thous inch
dwColumnSpace LONG(84) ! Avery Label inter column space = 84 thous inch
byColumn BYTE(1)
byRow BYTE(1)
Report REPORT,AT(0,0,1500,840),FONT('Arial',10,,FONT:regular,CHARSET:ANSI),PRE(RPT),PAPER(PAPER:A4),THOUS
Detail DETAIL,AT(0,0,1500,835),USE(?Detail),ABSOLUTE
BOX,AT(0,0,1500,835),USE(?BOX1),COLOR(0E0E0E0H),FILL(0E0E0E0H),LINEWIDTH(1)
STRING(@s20),AT(104,62,1302,156),USE(Q.szManSN),TRN,FONT(,8)
STRING(@s8),AT(104,250,,167),USE(Q.szPrefixNo),TRN
STRING(@s12),AT(104,427,1271,292),USE(Q.szBarCode),TRN,FONT('Code 3 de 9',18,,,CHARSET:SYMBOL)
END
END
CODE
!-- Set the Printer
!-- Printer{PROPPrint:Device} = myPrinter.szTargetPrinter
!-- Print Now
!--
Open(Report)
SETTARGET(Report)
LOOP i = 1 to RECORDS(Q)
GET(Q,i)
if ~ERRORCODE()
!-- Printing the box during testing is helpful for visual alignment purposes..
!--
!-- IF i % 2 = 0 then HIDE(?BOX1) ELSE UNHIDE(?BOX1).
!-- Set the position for "Absoloute" printing
!--
REPORT$?Detail{PROP:Xpos} = dwLeftMargin + ((byColumn-1) * dwLabelWidth)+ ((byColumn-1) * dwColumnSpace)
REPORT$?Detail{PROP:Ypos} = dwTopMargin + ((byRow-1) * dwLabelHeight)
REPORT$?Detail{PROP:Height} = dwLabelHeight
!-- Now Print the Detail ..
!--
Print(RPT:Detail)
!-- Increment column and row counters..
!--
if byColumn < 5
byColumn += 1
ELSE
byColumn = 1
byRow += 1
.
!-- Formfeed?
!-- Issue an ENDPAGE if this is label 65 and there are more to follow
!-- if i % 65 = 0
!-- ENDPAGE(REPORT)
!-- byRow = 1
!-- byColumn = 1
!-- .
.
.
Close(Report)
If you allow ?BOX1 to print during testing you can tweak dwTopMargin and dwLeftMargin to achieve perfect alignment.
Mission accomplished !