class tprinter and a dot-matrix printer

class tprinter and a dot-matrix printer

Postby kajot » Sun Mar 26, 2017 6:50 am

is it possible to print in text mode on a dot-matrix printer
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: class tprinter and a dot-matrix printer

Postby ukoenig » Sun Mar 26, 2017 3:33 pm

A customer of mine is using a old matrix-printer to print labels

Have a look at TDOSPRN ( source )

The following code will let you print directly to the printer from inside
any Fivewin program, like OLD DOS days. Those users that need DOS printing
speed can use this class instead of the TPrinter class.

This is a little sample of how to use the new class:

LOCAL oPrn

oPrn := TDosPrn():New("lpt1")

oPrn:StartPage() // optional
oPrn:Say(10,20, "This goes in line 10, column 20")
oPrn:EndPage() // optional

oPrn:End()

A little description of all the members of this class:

DATAs:
cPort: Printing port, by default "LPT1"
cCompress: String for compressed mode, by default "15"
cNormal: String for normal mode, by default "18"
cFormFeed: String for EJECT, by default "12"
hDC: Printing file Handle (Internal use)
nRow: Current printing row
nCol: Current pringing column
nLeftMargin: Left margin, by default 0
nTopMargin: Top margin, by default 0
lAnsiToOem: If .T. a Ansi to Oem translation is done automatically
whe printing, by default is .T.

METHODS:
New(cPort) Constructor, no comment
End() Destructor, no comment
StartPage() Begining of a page, this method is optional
EndPage() End of page, this method is optional if there is only one page
Command(c) Let you send any command to the printer without changing the
current row and col. The string to pass as a parameter should
content the ascii values of the command separated with commas,
for example, the command to reset Epson printers should
be: "27,69"
SetCoors(r,c) Let you change the current row and col is the equivalent of
SetPrc() of Ca-Clipper
NewLine() Increments the current row
Write(cText) Prints the string cText in the current row and column
Say(nRow ,; Prints the string cText in nRow, nCol
nCol ,; lAtoO indicates if the string should be transformed to Oem,
cText ,; by default is ::lAnsiToOem
lAtoO )
SayCmp() The same as the method Say but prints in compressed mode and
the row is updated accordly.

NOTE:
If you try to print on a row before the current one a EJECT will be
done automatically.

At the end of this class is a little function call WorkSheet that will make
the job of DOS printing a lot easier.

LKM changed behavior of how EJECT is handled, for real DOS simulation
In the same way if you try to print on the same row as the current, but
in a previous column from the current one a EJECT will be done automatically

TIP: make sure port name (\sharename part) is 8 chars or less, or you'll get a
DOS error 5 (Access denied) if printing across the network

Code: Select all  Expand view  RUN

cPORT :=  "LPT" + ltrim(str(I_VAR[8])) // port
oPrn  := TDosPrn():New(cPORT) // !!!!!!
oPrn:SetCoors(0,0)
oPrn:Command(I_VAR[9])         // German fonts
oPrn:Command(I_VAR[10])       // Font
i := 1
FOR i := 1 TO I_VAR[12]          // returns for distance between labels
     oPrn:Command(I_VAR[11])  // carriage return command
NEXT
oPrn:SetCoors(0,0)
oPrn:Say(1,25, d_Etti[1])         // Line 1
oPrn:Say(2,25, d_Etti[2])         // Line 2
oPrn:Say(3,25, d_Etti[3])         // Line 3
oPrn:Say(4,25, d_Etti[4])         // Line 4
oPrn:Say(5,25, d_Etti[5])         // Line 5
oPrn:Say(6,25, d_Etti[6])         // Line 6
i := 1
FOR i := 1 TO I_VAR[14]             // lines
     oPrn:Command(I_VAR[13])     // carriage command
oPrn:End()
 


regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: class tprinter and a dot-matrix printer

Postby Marc Venken » Mon Mar 27, 2017 6:56 pm

This is a sample for printing a invoice on a matrix printer. (the old way)

Maybe it has any use...

Code: Select all  Expand view  RUN
function druk_Ketting()

   Local nDruk:=0, nDrukafstand:= 0.5, nDrukstart:= 12.7
   cPagtitel = "GROOT"
   cDagboek = "VER"

   Rec_lock("factinfo")
      factinfo->factuur = oTellers:factnummer
      factinfo->toestand = "Factuur GR="+str(oTellers:factnummer,7)
      factinfo->Docstatus = "A"
   rec_unlock("factinfo")

   Public oPrn
   Public oF12,oF12B,oF12I,oF12U,oFlarge

   PRINTER oPrn NAME "Afdruk" // FROM USER //PREVIEW MODAL
   oPrn:setup()
   oPrn:setsize(2400,3050)

   DEFINE FONT oF12    NAME "ARIAL" SIZE 0, -9 OF oPrn
   DEFINE FONT oF12B   NAME "ARIAL" BOLD SIZE 0, -12 OF oPrn
   DEFINE FONT oF12I   NAME "ARIAL" ITALIC SIZE 0, -12 OF oPrn
   DEFINE FONT oF12U   NAME "ARIAL" UNDERLINE BOLD SIZE 0, -10 OF oPrn
   DEFINE FONT oFLarge NAME "ARIAL" BOLD SIZE 0, -18 OF oPrn

   oPrn:startpage()

   hoofding(oPrn,"KETTING",cPagTitel)  // afdruk hoofding
   nDruk = nDrukstart

   dbselectarea("DETAIL")

   detail->(dbgotop())
   nTotaal := 0
   cDrukbon = ""
   do while !detail->(eof())
      if nDruk >= 23.5
         oPrn:endpage()
         oPrn:startpage()
         hoofding(oPrn,"KETTING",cPagTitel)  // afdruk hoofding
         nDruk = nDrukstart
      endif
      If cDrukbon <> alltrim(detail->drukdoc)
         cDrukbon = alltrim(detail->drukdoc)
         nDruk += +.3
         oPrn:cmsay (nDruk,6.1,"Leveringsbon  " + cDrukbon,oF12)
         if factinfo->(dbseek(cDrukbon))
            If !empty(factinfo->bestelbon)
               oPrn:cmsay (nDruk,11,"Uw order " + alltrim(factinfo->bestelbon),oF12)
            EndIF
            Rec_lock("factinfo")
               factinfo->factuur = oTellers:factnummer
               factinfo->toestand = "Factuur GR="+str(oTellers:factnummer,7)
               factinfo->Docstatus = "A"
            rec_unlock("factinfo")
         endif
         factinfo->(dbseek(cDocnummer))
         nDruk += nDrukafstand+.3
      EndIF
      oPrn:cmsay (nDruk, 3.9 ,detail->refnummer,oF12)
      oPrn:cmsay (nDruk, 6.1 ,detail->benaming,oF12)
      oPrn:cmsay (nDruk,16.8 ,str(detail->aantal,9),oF12,,,,1)
      oPrn:cmsay (nDruk,18.5 ,str(detail->eenh_prijs,9,2),oF12,,,,1)
      oPrn:cmsay (nDruk,19.5 ,if(detail->korting <> 0, "-"+stzero(detail->korting,3,0),""),oF12,,,,1)
      oPrn:cmsay (nDruk,21.6 ,str(detail->totaal,9,2),oF12,,,,1)
      oPrn:cmsay (nDruk,22.6 ,"21",oF12,,,,1)
      nTotaal = nTotaal + detail->totaal

      nDruk += nDrukafstand
      detail->(dbskip())
   enddo
   if !empty(factinfo->voldaan)
      oPrn:cmsay (24 , 3 ,"Betaalwijze : "+factinfo->voldaan,oF12)
   endif

   //oPrn:cmsay (25   , 3 ,"-2 % korting op de goederenprijs bij betaling",oF12)
   //oPrn:cmsay (25.5 , 3 ,"     voor "+dtoc(date()+10)+"  - €"+str( (nTotaal*2/100),6,2),oF12)

   oPrn:cmsay (27.6 , 17.8 ,str(nTotaal,11,2),oF12b,,,,1)
   oPrn:cmsay (27.6 , 18.4 ,"21",oF12b)
   If upper(klant->btwjn) == "N"
      nNoBtw:= 0
      oPrn:cmsay (27.6 , 20.6 ,str(nNoBtw,11,2),oF12b,,,,1)
      oPrn:cmsay (27.6 , 22.6 ,str(nTotaal,11,2),oF12b,,,,1)
   else
      oPrn:cmsay (27.6 , 20.6 ,str(Btw(21,nTotaal),11,2),oF12b,,,,1)
      oPrn:cmsay (27.6 , 22.6 ,str(BtwIncl(21,nTotaal),11,2),oF12b,,,,1)
      cSom = alltrim(str(BtwIncl(21,nTotaal)))
      nPos = at(".",cSom)
      nSomEuro = val(substr(cSom,1,nPos-1))
      nSomCent = val(substr(cSom,nPos+1))
      cEuro = Numconv(nSomEuro)+ " EURO EN " + Numconv(nSomCent)+" CENT"
      oPrn:cmsay (28.8 , 3,"Waar en echt verklaard voor de som van",oF12)
      oPrn:cmsay (29.3 , 3,cEuro,oF12)
   EndIF

   oPrn:cmsay (28.7 , 19.3 ,dtoc(vervaldat()),oFLarge)

   oPrn:endpage()

   //oPrn:Preview()

   oF12:end();oF12B:end();oF12I:end();oF12U:end();oFlarge:end();oPrn:end()

return
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

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