Imprimir en rollo y matriz de punto

Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Tue Sep 21, 2021 4:14 am

Muchos saludos amigos.

Necesito imprimir facturas en formato de ticketa usando rollos de papel bond y en una impresora matricial.

Ya tengo la impresora funcionando con la TdosPrn pero no he podido controlar la impresion.

¿Que clase me sugieren como la mas adecuada? Que permita imprimir sin importar el largo de la factura y que no haga salto de pagina al final. Si la tdosprn me sirve, tendran un pequeño ejemplo que me ayude?

Quedo pendiente de sus gentiles opiniones.

Uso fw17.01 + xHarbour
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby leandro » Tue Sep 21, 2021 10:44 am

Amigo buenos días

Una idea

Code: Select all  Expand view


************************
*Imprimir Reporte D.O.S.
************************
FUNCTION pImDSFac()

Local Col:=Lin:=0
local vConFac:=1

cPorta := PrnGetPort()
cPrinter := PrinterPortToName( cPorta )
if empty(cPrinter)
   cPrinter := PrinterPortToName( "USB002" )
   if empty(cPrinter)
      cPrinter := PrinterPortToName( "USB001" )
   endif
endif

IMfac := TDosPrn():New(".\dbfs\lamtem\tempo.txt")
IMfac:StartPage()

 IMfac:say(lin,col,chr(027) + chr( 112 ) + chr( 000) + chr(100) + chr( 250 )) //Abre el cajon

 IF oLamcla:vImpue=".T."
   IMfac:say(lin,col,CHR(27)+CHR(33)+CHR(25))
   lin++
   IMfac:say(lin,col,oLamcla:vGnom)
   lin++
   IMfac:say(lin,Col,"NIT: "+alltrim(oLamcla:vGnit))
   lin++
   IMfac:say(lin,Col,CHR(27)+CHR(33)+CHR(4))
   lin++
   IMfac:say(lin,col,subs(oLamcla:vCaRes,1,34))
   if !Empty(alltrim(subs(oLamcla:vCaRes,35,34)))
     lin++
     IMfac:say(lin,col,subs(oLamcla:vCaRes,35,34))
   endif
   if !Empty(alltrim(subs(oLamcla:vCaRes,69,34)))
     lin++
     IMfac:say(lin,col,subs(oLamcla:vCaRes,69,34))
   endif
   if !Empty(alltrim(subs(oLamcla:vCaRes,103,34)))
     lin++
     IMfac:say(lin,col,subs(oLamcla:vCaRes,103,34))
   endif
   if !Empty(alltrim(subs(oLamcla:vCaRes,137,34)))
     lin++
     IMfac:say(lin,col,subs(oLamcla:vCaRes,137,34))
   endif
   if !Empty(alltrim(subs(oLamcla:vCaRes,171,34)))
     lin++
     IMfac:say(lin,col,subs(oLamcla:vCaRes,171,34))
   endif
   lin++
   IF oLamcla:vDire=nil
     IMfac:say(lin,Col,"DIRECCION:")
   ELSE
     IMfac:say(lin,Col,subs(oLamcla:vDire,1,34))
   ENDIF
   lin++
   IMfac:say(lin,Col,"TELEFONO: "+alltrim(if(oLamcla:vTele=nil,oLamcla:vTele:=space(0),oLamcla:vTele)))
   lin++
   lin++
   IMfac:say(lin,Col,"FACTURA DE VENTA No.: "+alltrim(str(vConPago)))
   lin++
 ENDIF
 IMfac:say(lin,Col,"FECHA: "+alltrim(dtoc(oLamcla:vCafec))+" "+subs(time(),1,8))
 lin++

 SELE d_forma
 Dbgotop()
 LOCATE FOR d_forma->Tipod=6
 IF FOUND()
   IMfac:say(lin,Col,"CLIENTE : "+alltrim(oLamcla:vSterc))
   lin++
   IMfac:say(lin,Col,"CEDULA  : "+alltrim(oLamcla:vGTerc))
   lin++
 ENDIF

 lin++
 IF oLamcla:vImpue=".T."
   IMfac:say(lin,Col,"REFERE TL PRODUCTO    IVA   CANT   VALOR  ")
 ELSE
   IMfac:say(lin,Col,"REFERE TL PRODUCTO    DES   CANT   VALOR  ")
 ENDIF
 lin++
   IMfac:say(lin,Col,"====== == =========== ===== ====== =======")
 lin++

 SELE d_caja
 SET FILT TO d_caja->Signo="s"
 Dbgotop()
 Do While !eof()

  vDc:=subs(d_caja->Codig,1,7)
  vDt:=subs(d_caja->Talla,1,2)
  vDd:=subs(d_caja->Descr,1,13)
  vDa:=transform(d_caja->Canti,"99999")
  vDp:=transform(d_caja->PVpub,"9,999,999")
  vDj:=transform(d_caja->PoIva,"99")
  IMfac:say(lin,Col,vDc+" "+vDt+" "+vDd+" "+vDj+"% "+vDa+" "+vDp)
  lin++
  Skip
 Enddo
 lin++
 IMfac:say(lin,Col,"ARTICULOS COMPRADOS: "+transform(oLamcla:vCaCan,"99999"))
 lin++

 IMfac:say(lin,col,CHR(27)+CHR(33)+CHR(25))

 //ESta parte se encarga de imprimir el descuento en la factura si lo tiene
 if vGDesc#0
   IMfac:say(lin,Col,"SUBTOTAL......................"+transform(oLamcla:vCatot,"9,999,999"))
   lin++
   IMfac:say(lin,Col,"DESCUENTO....................."+transform(vGDesc,"9,999,999"))
   lin++
   IMfac:say(lin,Col,"TOTAL........................."+transform(oLamcla:vCatot-vGDesc,"9,999,999"))
   lin++
 else
   IMfac:say(lin,Col,"TOTAL........................."+transform(oLamcla:vCatot,"9,999,999"))
   lin++
 endif
 IMfac:say(lin,Col,CHR(27)+CHR(33)+CHR(4))


 if vCambio#0
   IMfac:say(lin,Col,"TOTAL DEVOLUCIONES Y CAMBIOS.."+transform(vCambio,"9,999,999"))
   lin++
   IMfac:say(lin,Col,"TOTAL A PAGAR ................"+transform(oLamcla:vCatot-vCambio,"9,999,999"))
   lin++

 endif


 //imprime el detalle tributario si lo tiene
 SELE d_tari
 Dbgotop()
 SUM d_tari->Impue TO vTImpues
 IF vTImpues#0

     IF oLamcla:vImpue=".T."
       lin++
       IMfac:say(lin,Col,"DETALLE TRIBUTARIO")
       lin++
       IMfac:say(lin,Col,"TARIFA     BASE          IVA  ")
       lin++
       IMfac:say(lin,Col,"======== =========== =========== ")
       lin++

       SELE d_tari
       Dbgotop()
       Do While !eof()
        vTa:=d_tari->Tarif
        vIm:=transform(d_tari->Impue,"9,999,999")
        vBa:=transform(d_tari->BaIva,"9,999,999")
        vPo:=d_tari->PoIva
        IF vPo#0
          IMfac:say(lin,Col,vTa+"%     "+vBa+" "+vIm)
          lin--
        ENDIF
        lin++
        Skip
       Enddo
     ENDIF
 ENDIF

 lin=lin+2
 IMfac:say(lin,Col,"FORMA DE PAGO   No.APROV   #C     VALOR")
 lin++
 IMfac:say(lin,Col,"=============== ========== == =========")
 lin++

 SELE d_forma
 Dbgotop()
 Do while !eof()
   vApr:=subs(d_forma->Aprov,1,10)
   vCuo:=subs(d_forma->Cuota,1,2)
   vVal:=transform(d_forma->ValDo,"9,999,999")

   vTip:=d_forma->Tipod
   IF vTip=1
     vCad:="1.EFECTIVO"
   ELSEIF vTip=2
     vCad:="2.CHEQUE"
   ELSEIF vTip=3
     vCad:="3.TARJ.DEB."
   ELSEIF vTip=4
     vCad:="4.TARJ.CRE."
   ELSEIF vTip=5
     vCad:="5.OTRO"
   ELSEIF vTip=6
     vCad:="6.CR.FA.CODENSA"
   ENDIF
   vTi2:=subs(vCad,1,15)

   IMfac:say(lin,Col,vTi2+" "+vApr+" "+vCuo+" "+vVal)
   lin++

   SELE d_forma
   Skip
 EndDo
 lin++

 IMfac:say(lin,Col,"EFECTIVO PESOS: "+transform(oLamcla:vCGTe1,"9,999,999"))
 lin++
 IMfac:say(lin,Col,"SU CAMBIO     : "+transform(oLamcla:vCSTe2,"9,999,999"))

 //imprime el detalle tributario si lo tiene
 SELE d_camb
 Dbgotop()
 SUM d_camb->Basei TO vTIcambi
 IF vTIcambi#0

       lin=lin+2
       IMfac:say(lin,Col,"DETALLE DEVOLUCIONES")
       lin++
       IMfac:say(lin,Col,"NOTA CREDITO FACTURA")
       lin++
       IMfac:say(lin,Col,"PRODUCTO    CANT. VALOR  ")
       lin++
       IMfac:say(lin,Col,"=========== ===== =========")
       lin++
       SELE d_camb
       Dbgotop()
       Do While !eof()
        vTa:=d_camb->Artic
        vIm:=d_camb->Descr
        vBa:=transform(d_camb->Basei,"9,999,999")
        IMfac:say(lin,Col,alltrim(vTa)+" "+alltrim(vIm)+" "+vBa)
            lin++
        Skip
       Enddo
 ENDIF


 lin:=lin+2
 IMfac:say(lin,Col,"ATENDIDO POR: "+alltrim(oLamcla:vNous))
 lin++
 IMfac:say(lin,Col,"CAJA: "+oLamcla:vCajas)
 lin:=lin+2
// IMfac:say(lin,Col,"LA ROPA INTERIOR Y PROMOCIONES NO TIENEN")
// lin++
// IMfac:say(lin,Col,"CAMBIO")
// lin:=lin+2
 IMfac:say(lin,Col,"GRACIAS POR SU COMPRA")
 lin:=lin+2
// IMfac:say(lin,Col,"Impreso por LYMA - Sistemas de Informaciòn")
 lin:=lin+10
 IMfac:say(lin,Col,"")//Es como una FEED de papel para que el corte sea mas facil
 lin++
 IMfac:say(lin,Col,CHR(27)+CHR(105)) // corte de papel

IMfac:EndPage()
IMfac:End()

while vConFac<=vGCopfac
   PrintFileRaw( cPrinter, TrueName(".\dbfs\lamtem\tempo.txt"), "Impresión Caja" )
   vConFac++
enddo

Return nil
 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Imprimir en rollo y matriz de punto

Postby cmsoft » Tue Sep 21, 2021 2:38 pm

El ejemplo de Leandro es excelente para imprimir con TdosPrn.
Te dejo otra opcion, para imprimir con la clase TPrint también.
Code: Select all  Expand view

//oApp tiene los datos del comercio
// oQryVen1 tiene los datos del encabezado de la venta
// oQryDet1 tiene los datos del detalle del ticket
               //config:fon define el tamaño del fuente que quieres usar

               DEFINE FONT oFont   NAME "COURIER NEW"       SIZE config:fon,config:fon*2.5
               DEFINE FONT oFont1  NAME "CALIBRI"                SIZE config:fon*1.5,config:fon*4 BOLD
               PRINT oPrn TO ALLTRIM(oQryP:impresoraT) // oQryP:impresora es el nombre de la impresora en Windows
                  PAGE                                  
                     nRow := 2
                     @ 0,1 PRINT TO oPrn IMAGE "logo.jpg" SIZE 5, 1.5 CM  //Imprimo el logo
                     @ 0, .1 PRINT TO oPrn TEXT ALLTRIM(oApp:nomb_emp) ;
                                  SIZE 8,.5 CM FONT oFont1 ALIGN "C" LASTROW nRow
                     @ nRow, .1 PRINT TO oPrn TEXT ALLTRIM(oApp:dire_emp) ;
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"    
                     @ nRow, .1 PRINT TO oPrn TEXT ALLTRIM(oApp:tipo_iva) ;
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"

                     @ nRow, .1 PRINT TO oPrn TEXT "CUIT:"+oApp:cuit_emp ;
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"
                     @ nRow, .1 PRINT TO oPrn TEXT "Ing.br:"+ALLTRIM(oApp:ingb_emp);
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"
                     @ nRow, .1 PRINT TO oPrn TEXT "Inic.Act.:"+DTOC(oApp:inac_emp);
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"
                                 
                     @ nRow, .1 PRINT TO oPrn TEXT "TICKET" +cNumComp ;
                                  SIZE 8,.5 CM FONT oFont1 LASTROW nRow ALIGN "C"
                     @ nRow, .1 PRINT TO oPrn TEXT "Fecha Emision:" + +DTOC(oQryVen1:fecha);
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "C"                                                  
                     @ nRow, .1 PRINT TO oPrn TEXT ALLTRIM(oQryVen1:nombre);
                                  SIZE 8,1 CM FONT oFont LASTROW nRow ALIGN "L"                                  
                     @ nRow, .1 PRINT TO oPrn TEXT oQryVen1:cuit;
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "L"
                     @ nRow, .1 PRINT TO oPrn TEXT oQryVen1:coniva;
                                  SIZE 8,.5 CM FONT oFont LASTROW nRow ALIGN "L"
                     @ nRow, .1 PRINT TO oPrn TEXT oQryVen1:direccion;
                                  SIZE 8,1 CM FONT oFont LASTROW nRow ALIGN "L"
                     nRow1 := nRow + .5                    
                     @ nRow1, 00.02 PRINT TO oPrn TEXT "Descripcion";
                                  SIZE 3.5,.5 CM FONT oFont LASTROW nRow ALIGN "L"
                     @ nRow1, 03.60 PRINT TO oPrn TEXT "Cant";
                                  SIZE .9,.5 CM FONT oFont LASTROW nRow ALIGN "R"
                     @ nRow1, 04.62 PRINT TO oPrn TEXT "Unit";
                                  SIZE 1,.5 CM FONT oFont LASTROW nRow ALIGN "R"
                     @ nRow1, 05.66 PRINT TO oPrn TEXT "Total";
                                  SIZE 1.4,.5 CM FONT oFont LASTROW nRow ALIGN "R"
                     oQryDet1:GoTop()  
                     nRow := nRow + .2                    
                     FOR i = 1 TO oQryDet1:nRecCount          
                         nRow1 := nRow
                         @ nRow1, 00.00 PRINT TO oPrn TEXT ALLTRIM(oQryDet1:detart);
                              SIZE 3.5,.5 CM FONT oFont LASTROW nRow ALIGN "L"
                         @ nRow1, 03.60 PRINT TO oPrn TEXT STR(oQryDet1:cantidad,06,2);
                              SIZE .9,.5 CM FONT oFont  ALIGN "R"
                         @ nRow1, 04.66 PRINT TO oPrn TEXT STR(oQryDet1:punit,10,2) ;
                              SIZE 1,.5   CM FONT oFont ALIGN "R"
                         @ nRow1, 05.80 PRINT TO oPrn TEXT STR(oQryDet1:total,10,2);
                              SIZE 1.4,.5 CM FONT oFont LASTROW nRow ALIGN "R"                    
                         oQryDet1:Skip()                    
                      NEXT                                          
                      nRow1 := nRow
                      nRow := nRow + .3
                      @ nRow, .1 PRINT TO oPrn TEXT "Total $ " + STR(oQryVen1:importe,10,2);
                                  SIZE 8,.5 CM FONT oFont1 LASTROW nRow ALIGN "L"                    
                     @ nRow,.1 PRINT TO oPrn TEXT "...";
                              SIZE 8,.5 CM FONT oFont1 LASTROW nRow ALIGN "L"              
                  ENDPAGE
               ENDPRINT
 
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 12:16 am

Leandro,

Gracias por el aporte. Probé tu código y funciona bien, pero no me resuelve el problema que tengo,

El problema es el siguiente:

Todo el proceso de impresion con TDosPrn se ejecuta sin problemas ni errores.

Incluso puedo hacer un PREVIEW (usando una aplicacion de terceros LTFViewr5u.exe) y la factura se ve perfecta, como debe ser y se crea el .TXT.

hasta aqui todo bien, pero cuando mando a imprimir en la impresora se presenta el inconveniente, todo se ejecuta bien, pero no hace los saltos de linea.

La factura completa se imprime en la misma linea, Unas sobre otras.

La impresora esta super probada con otras aplicaciones como word, notepad, y otras y funciona muy bien. No es problema de la impresora.
Es una Tally Dascom 1125

Aca dejo el segmento de codigo que estoy usando, disculpen por el desorden, pero cuando logre que funcione me toca "limpiar" y ordenar el codigo.

Code: Select all  Expand view
#include "Neuro32.ch"

#define RT_RCDATA 10

Static oMeter, oWndMeter

Static cSalida

Static nRecTotal, nCiclo, nActual, nSalida

*******************************************************************************************************
Static cLogFile, cLocalProcess, nSecuencia
*******************************************************************************************************
Function Fnct_PrintFacToPaper(cGetNumeroDoc)

    cSalida   := alltrim(cGetNumeroDoc)+'.prn'

    nCiclo    := 1
    nSalida   := 1
    nRecTotal := 10000

    nSalida:=Fnct_InfoSalida()

    Do Case
        Case nSalida=1
          cSalida := alltrim(cGetNumeroDoc)+".txt"
        Case nSalida=2.or.nSalida=3
           cSalida:=''
           shellexecute( 'net use lpt1 \\%computername%\Generic / Text Only (Copiar 1)')  //'net use lpt1 \\%computername%\Tally Dascom 1125'
        Case nSalida=3
         *cSalida := 'lpt1'
        Case nSalida=4
         return .f.
    EndCase


  DEFINE window  oWndMeter FROM 13,26 TO 20,70  TITLE "Imprimiendo Documento de Venta..." color 'n/w+' noiconize nozoom;
                                                                                            nosysmenu
    @ 2,2 METER oMeter VAR nActual TOTAL nRecTotal OF oWndMeter color selcolor(5),selcolor(1)

  ACTIVATE window oWndMeter ON INIT ShowControls()

    nActual:= 1
    nCiclo := 1

    Fnct_PrintJob(cGetNumeroDoc)

return .t.


**************************************************************************************************************************************
Static Function FNCT_PrintJob(cGetNumeroDoc)

    Local oPrn
    Local cComando
    Local nRow, nCol, nError

    nRow  :=0
    nCol  :=0

    if nSalida>1
        oPrn:=tdosprn():new()
      PRINT oPrn  NAME ("Documento De Venta") TO "Generic / Text Only (Copiar 1)" //"Tally Dascom 1125"//
     else
        oPrn:=tdosprn():new(cSalida)
    endif

    *oPrn:Setup()    activar al terminar
  oPrn:StartPage()

        oPrn:Say(   nRow , 00 , alltrim(_cCompanyName ) )
        oPrn:Say( ++nRow , 00 , alltrim(_cCompanyRif  ) )
        oPrn:Say( ++nRow , 00 , repl('-',28)  )
        oPrn:Say( ++nRow , 00 , alltrim(_cDireccion1  ) )
        oPrn:Say( ++nRow , 00 , alltrim(_cDireccion2  ) )
        oPrn:Say( ++nRow , 00 , alltrim(_cTelefonos   ) )
        oPrn:Say( ++nRow , 00 , alltrim(_cCiudad      )+', '+alltrim(_cEstado))
        oPrn:Say( ++nRow , 00 , alltrim(_cMail        ) )
        oPrn:Say( ++nRow , 00 , alltrim(_cWebSite     ) )
        oPrn:Say( ++nRow , 00 , 'Fecha: '+dToc(date()) )
        oPrn:Say( ++nRow , 00 , 'Factura: '+alltrim(cGetNumeroDoc) )

      nActual++
      oMeter:Set( nActual)
      ShowControls()

    oWndMeter:End()
    oMeter:End()

      *oPrn:say(++nRow,00,CHR(27)+CHR(105)) // corte de papel   NO FUNCIONA
     *oPrn:Preview()   NO FUNCIONA

  oPrn:Endpage()
   
  oPrn:End()

    if nSalida=1
      cComando= "LTFViewr5u "+cSalida
      nError=waitrun(cComando)
    if nError >32
      msginfo("Error: No se encuentra disponible El modulo: {LTFViewr5u.exe} para Impresiones  por pantalla, Avisar al supervisor")
    endif
 endif


return .t.

*****************************************************************************************************************************************
static function ShowControls()

     oMeter:Set( nActual)

return nil
 



Y esta es la clase TDosPrn que estoy usando:

Code: Select all  Expand view
/*
ÚÄ Programa ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³   Aplication: Class TDosPrint                                            ³
³         File: TDOSPRN.PRG                                                ³
³       Author: Ignacio Ortiz de Z£¤iga Echeverr¡a                         ³
³          CIS: Ignacio Ortiz (Ignacio_Ortiz)                              ³
³     Internet: http://www.ozs.com                                         ³
³         Date: 09/13/96                                                   ³
³         Time: 20:20:07                                                   ³
³    Copyright: 1997 by Ortiz de Zu¤iga, S.L.                              ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

NOTES:

This peace of software is freeware and is not part of FiveWin.

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.

The use of the class is very easy and is very similar to the TPrinter class
of Fivewin, but we have not create any command to avoid the use of any
static vars.

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:

DATA:

 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 on 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.

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

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

Enjoy it!
*/


#include "fivewin.ch"

#translate nTrim(<n>)  => AllTrim(Str(<n>,10,0))

//----------------------------------------------------------------------------//

CLASS TDosPrn

     DATA LastError
     DATA cPort, cCompress, cNormal, cFormFeed, cBuffer     AS STRING
     DATA hDC, nRow, nCol, nLeftMargin, nTopMargin          AS NUMBER
     DATA lAnsiToOem                                        AS LOGICAL

     METHOD New(cPort) CONSTRUCTOR

     METHOD End()

     METHOD StartPage()  VIRTUAL
     METHOD EndPage()

     METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5)

     METHOD SetCoors(nRow, nCol)

     METHOD NewLine()       INLINE (::cBuffer += CRLF ,;
                                    ::nRow++          ,;
                                    ::nCol    := 0     )

     METHOD Write(cText, lAToO) ;
            INLINE (iif(lAtoO == NIL, lAtoO := .T.,),;
                    ::cBuffer += iif(lAtoO, AnsitoOem(cText), cText) ,;
                    ::nCol    += len(cText)                           )

     METHOD Say(nRow, nCol, cText)

     METHOD SayCmp(nRow, nCol, cText)

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New(cPort, lFile) CLASS TDosPrn

     DEFAULT cPort := "LPT1" ,;
             lFile := .T.

     cPort := Upper(cPort)

     ::cCompress   := "15"
     ::cNormal     := "18"
     ::cFormFeed   := "12"
     ::cBuffer     := ""
     ::nLeftMargin := 0
     ::nTopMargin  := 0
     ::nRow        := 0
     ::nCol        := 0
     ::lAnsiToOem  := .T.
     ::cPort       := cPort+iif(!"."$cPort,".PRN","")
     ::hDC         := fCreate(::cPort)
     ::LastError   := 0

     IF ::hDC < 0
          ::LastError := fError()
     ENDIF

RETURN NIL

//----------------------------------------------------------------------------//

METHOD End() CLASS TDosPrn

     IF !empty(::nRow+::nCol)
          ::EndPage()
     ENDIF

     ::LastError := 0

     IF !fClose(::hDC)
          ::LastError := fError()
     ENDIF

RETURN NIL

//----------------------------------------------------------------------------//

METHOD EndPage() CLASS TDosPrn

     LOCAL nFor, nLen, nSec
     LOCAL lError

     ::Command(::cFormFeed)

     ::LastError := 0

     IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
          ::LastError := fError()
     ENDIF

     ::cBuffer := ""
     ::nRow    := 0
     ::nCol    := 0

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5) CLASS TDosPrn

     LOCAL cCommand, cToken, cString
     LOCAL nToken

     cString  := cStr1

     IF cStr2 != NIL
          cString += ","+cStr2
     ENDIF

     IF cStr3 != NIL
          cString += ","+cStr3
     ENDIF

     IF cStr4 != NIL
          cString += ","+cStr4
     ENDIF

     IF cStr5 != NIL
          cString += ","+cStr5
     ENDIF

     cCommand := ""
     nToken   := 1

     DO WHILE !Empty(cToken := StrToken(cString, nToken++, ","))
          cCommand += Chr(Val(cToken))
     ENDDO

     ::cBuffer += cCommand

RETURN NIL

//----------------------------------------------------------------------------//

METHOD SetCoors(nRow, nCol) CLASS TDosPrn

     nRow += ::nTopMargin
     nCol += ::nLeftMargin

     IF ::nRow > nRow
          ::EndPage()
          ::StartPage()
     ENDIF

     IF nRow == ::nRow  .AND. nCol < ::nCol
          ::EndPage()
          ::StartPage()
     ENDIF

     DO WHILE ::nRow < nRow
          ::NewLine()
     ENDDO

     IF nCol > ::nCol
          ::Write(Space(nCol-::nCol))
     ENDIF

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Say(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     ::SetCoors(nRow, nCol)
     ::Write(cText, lAToO)

RETURN NIL

//----------------------------------------------------------------------------//

METHOD SayCmp(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     ::SetCoors(nRow, nCol)
     ::Command(::cCompress)
     ::cBuffer += iif(lAToO, AnsitoOem(cText), cText)
     ::nCol    += Int(len(cText)/1.7+.5)
     ::Command(::cNormal)

RETURN NIL

//----------------------------------------------------------------------------//

FUNCTION WorkSheet(cPort)

     LOCAL oPrn
     LOCAL cLine
     LOCAL nFor

     cLine := ""

     FOR nFor := 0 TO 7
          cLine += Str(nFor,1)+Replicate(".",9)
     NEXT

     cLine := Substr(cLine,3)

     oPrn := TDosPrn():New(cPort)

     oPrn:StartPage()

     FOR nFor := 0 TO 65
          oPrn:Say(nFor,0,StrZero(nFor,2)+cLine)
     NEXT

     oPrn:EndPage()

     oPrn:End()

RETURN NIL
 


Otra cosa extraña es que la clase me arroja error al querer usar por ejemplo,

NewLine()
SayCmp()
SetCoors()

Entre otras.

Alguien sabria explicarme que esta mal o que estoy haciendo mal?

Gracias.


CESAR, gracias tambien por tu mano amiga, no pude probar tu codigo porque no tengo la clase TPRINT.

Podrias informarme donde puedo descargarla?


FW17.01 +xHARBOUR
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 12:20 am

Tambien probe con esta TDosPrn que es un poco diferente y mas actual, y el problema persiste

Code: Select all  Expand view
/*
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
*/


#include "FiveWin.ch"
#include "FileIO.ch"

#xtranslate nTrim( <n>, <i>, <d> )  => AllTrim( Str( <n>, <i>, <d> ) )

#define PF_BUFLEN   2048

#define iEJECT       "12"

// Generic Escape Codes for Laser Printes (HP Compatible)

#define iL_COMPRESS  Chr(27) + "&l 2a 0O" + Chr(27) + "(10U" + Chr(27) + "(s 0p 16.67h 8.5v 0s 0b 3T"
#define iL_NORMAL    Chr(27) + "&l 2a 0O" + Chr(27) + "(10U" + Chr(27) + "(s 0p 10.00h 12.0v 0s 0b 3T"
#define iL_RESET     Chr(27) + "E"

// Generic Escape Codes for Matrix Printers (Epson Compatible)

#define iM_COMPRESS  "15"
#define iM_NORMAL    "18"
#define iM_RESET     Chr(27) + "@"

//----------------------------------------------------------------------------//

CLASS TDosPrn

   DATA LastError
   DATA cPort, cCompress, cNormal, cFormFeed, cBuffer AS String
   DATA hDC, nRow, nCol, nLeftMargin, nTopMargin      AS NUMERIC
   DATA lAnsiToOem                                    AS LOGICAL
   DATA cReset                                        AS String
   DATA lFile                                         AS LOGICAL
   DATA nLPP                                          AS NUMERIC
   DATA bNewPage
   DATA nPage                                         AS NUMERIC
   DATA bPageChange
   DATA bOnClose
   DATA lPrnError                                     AS LOGICAL INIT .F.
   DATA lPrnSelect                                    AS LOGICAL INIT .F.
   DATA lPaperOut                                     AS LOGICAL INIT .F.
   DATA lDataAck                                      AS LOGICAL INIT .F.
   DATA lPrnBusy                                      AS LOGICAL INIT .F.
   DATA nLPTBase                                      AS NUMERIC

   METHOD New( cPort, lFile, lLaser, nLPP, bNewPage ) CONSTRUCTOR

   METHOD End( lReset, lEject )

   METHOD StartPage()  VIRTUAL
   METHOD EndPage( lReset, lEject )

   METHOD Command( cStr1, cStr2, cStr3, cStr4, cStr5 )

   METHOD SetCoors( nRow, nCol )

   METHOD NewLine()       INLINE ( ::cBuffer += CRLF,;
                                   ::nRow++         ,;
                                   ::nCol    := 0 )

   METHOD Write( cText, lAToO ) ;
          INLINE ( If( lAtoO == Nil, lAtoO := .T., Nil ),;
                   ::cBuffer += If( lAtoO, AnsitoOem( cText ), cText ),;
                   ::nCol    += Len( cText ) )

   METHOD Say( nRow, nCol, cText, lAToO )

   METHOD SayNow( nRow, nCol, cText, lAToO )

   METHOD SayCmp( nRow, nCol, cText, lAToO )

   METHOD PrintFile( cFile )

   METHOD Esc2Cmd( cString )

   METHOD PrinterStatus()

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cPort, lFile, lLaser, nLPP, bNewPage ) CLASS TDosPrn

   Local aPorts := { { "LPT1",  888 }, ;         // 378h
                     { "LPT2",  632 }, ;         // 278h
                     { "COM1", 1016 }, ;         // 3f8h
                     { "COM2",  760 }  }         // 2f8h
   Local nPos

   DEFAULT cPort  := "LPT1" ,;
           lFile  := .T.   ,;                    // not used; kept here for compatibility
           lLaser := .F.   ,;
           nLPP   := 66

   cPort := Upper( cPort )

   If lLaser
      ::cCompress := ::Esc2Cmd( iL_COMPRESS )
      ::cNormal   := iL_NORMAL
      ::cReset    := ::Esc2Cmd( iL_RESET )
   Else
      ::cCompress := iM_COMPRESS
      ::cNormal   := iM_NORMAL
      ::cReset    := ::Esc2Cmd( iM_RESET )
   Endif
   ::cFormFeed    := iEJECT
   ::cBuffer      := ""
   ::nLeftMargin  := 0
   ::nTopMargin   := 0
   ::nRow         := 0
   ::nCol         := 0
   ::lAnsiToOem   := .T.
   ::cPort        := cPort + If( ! "." $ cPort .and. ! "\\" $ cPort, ".PRN", "" )  // considers the port can be a network route (\\computername\sharename)
   ::hDC          := -1  // FCreate( ::cPort ) moved down, after port checking is done
   ::LastError    := 0
   ::lFile        := ! ( Left( cPort, 3 ) == "LPT" .or. Left( cPort, 3 ) == "COM" .or. Left( cPort, 3 ) == "PRN" )
   ::nLPP         := nLPP
   ::bNewPage     := bNewPage
   ::nPage        := 1
   ::nLPTBase     := 0

   If ! ::lFile
      nPos := Max( 1, AScan( aPorts, {|aSub| aSub[1] == cPort } ) )  // LPT1 or PRN considered default
      ::nLPTBase := aPorts[nPos,2]
      ::PrinterStatus()
   Endif

   If ::lFile .or. ( ! ::lPrnBusy .and. ! ::lPaperOut ) /*;  // reliable with matrix, not laser printers
         If( cPort == "LPT1", IsPrinter(), ! ::lPaperOut )*/

      ::hDC := FCreate( ::cPort )                // 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
      If ::hDC < 0
         ::LastError := FError()
      Endif
   Else
      If ::lPrnBusy .and. ::lPaperOut .and. ! ::lPrnSelect
         ::LastError := 28                       // "Printer out of paper"
      Elseif ::lPrnBusy .and. ! ::lPaperOut
         ::LastError := 29                       // "Write fault" (Printer off line or not powered on)
      Else
         ::LastError := 6                        // "Invalid handle"
      Endif
   Endif

Return Self

//----------------------------------------------------------------------------//

METHOD End( lReset, lEject ) CLASS TDosPrn

   DEFAULT lReset := .F.

   If ! Empty( ::nRow + ::nCol )
      ::EndPage( lReset, lEject )
   Elseif lReset
      ::Command( ::cReset )
   Endif
   ::nPage--

   ::LastError := 0

   If ! FClose( ::hDC )
      ::LastError := FError()
   Endif

   If ::bOnClose # Nil
      Eval( ::bOnClose, Self )
   Endif

Return ( ::LastError == 0 ) // .T. == Finished OK  .F. Finished with some error

//----------------------------------------------------------------------------//

METHOD EndPage( lReset, lEject ) CLASS TDosPrn

   LOCAL nFor, nLen, nSec
   LOCAL lError

   DEFAULT lReset := .F., lEject := .T.

   If( lReset, ::Command( ::cReset ), Nil )
   If( lEject, ::Command( ::cFormFeed ), Nil )

   ::LastError := 0

   ::nPage ++
   If FWrite( ::hDC, ::cBuffer ) < Len( ::cBuffer )
      ::LastError := FError()
   Endif
   ::cBuffer := ""
   ::nRow    := 0
   ::nCol    := 0

   If ::bPageChange # Nil
      Eval( ::bPageChange, Self )
   Endif

Return Self

//----------------------------------------------------------------------------//

METHOD Command( cStr1, cStr2, cStr3, cStr4, cStr5 ) CLASS TDosPrn

   LOCAL cCommand, cToken, cString
   LOCAL nToken

   cString := cStr1

   If cStr2 != Nil
      cString += "," + cStr2
   Endif

   If cStr3 != Nil
      cString += "," + cStr3
   Endif

   If cStr4 != Nil
      cString += "," + cStr4
   Endif

   If cStr5 != Nil
      cString += "," + cStr5
   Endif

   cCommand := ""
   nToken   := 1

   Do While ! Empty( cToken := StrToken( cString, nToken ++, "," ) )
      cCommand += Chr( Val( cToken ) )
   Enddo

   ::cBuffer += cCommand

Return Self

//----------------------------------------------------------------------------//

METHOD SetCoors( nRow, nCol ) CLASS TDosPrn

   nRow += ::nTopMargin
   nCol += ::nLeftMargin

   If nRow > ::nLPP .and. ::bNewPage # Nil
      ::EndPage()
      Eval( ::bNewPage, Self )
      nRow := ::nRow + ::nTopMargin
   Elseif ::nRow > nRow                        // if converted in elseif
      ::EndPage()
      ::StartPage()
   Endif

   If nRow == ::nRow .and. nCol < ::nCol
// This is the way to mimic the DOS behavior (just inserting a Carriage Return)...
      ::cBuffer += Chr(13)
// ...not this one
      /*::EndPage()
      ::StartPage()*/

   Endif

   Do While ::nRow < nRow
      ::NewLine()
   Enddo

   If nCol > ::nCol
      ::Write( Space( nCol - ::nCol ) )
   Endif

Return Self

//----------------------------------------------------------------------------//

METHOD Say( nRow, nCol, cText, lAToO ) CLASS TDosPrn

   DEFAULT lAToO := ::lAnsiToOem

   ::SetCoors( nRow, nCol )
   ::Write( cText, lAToO )

Return Self

//----------------------------------------------------------------------------//

METHOD SayNow( nRow, nCol, cText, lAToO ) CLASS TDosPrn

::Say( nRow, nCol, cText, lAToO )

::LastError := 0

If FWrite( ::hDC, ::cBuffer ) < Len( ::cBuffer )
   ::LastError := FError()
Endif
::cBuffer := ""

Return Nil

//----------------------------------------------------------------------------//

METHOD SayCmp( nRow, nCol, cText, lAToO ) CLASS TDosPrn

   DEFAULT lAToO := ::lAnsiToOem

   ::SetCoors( nRow, nCol )
   ::Command( ::cCompress )
   ::cBuffer += If( lAToO, AnsitoOem( cText ), cText )
   ::nCol    += Int( Len( cText ) / 1.7 + 0.5 )
   ::Command( ::cNormal )

Return Self

//----------------------------------------------------------------------------//

METHOD PrintFile( cFile ) CLASS TDosPrn

   Local hFile, nRead, cBuffer, lRetVal := .F., nCnt := 0

   hFile := FOpen( cFile, FO_READ )

   If lRetVal := ( hFile # -1 )

      cBuffer := Space( PF_BUFLEN )

      Repeat
         nRead := FRead( hFile, @cBuffer, PF_BUFLEN )
         If FWrite( ::hDC, Left( cBuffer, nRead ) ) < nRead
            ::LastError := FError()
            lRetVal := ::LastError == 0
            Exit
         Endif
         If ( ++ nCnt % 10 ) == 0
            SysRefresh() ; nCnt := 0
         Endif
      Until nRead == 0 //PF_BUFLEN

      FClose( hFile )
   Else
      ::LastError := FError()
   Endif

Return lRetVal

//----------------------------------------------------------------------------//

METHOD Esc2Cmd( cString ) CLASS TDosPrn
   Local cAscii := "", nI, nLen

   cString := StrTran( cString, " ", "" )
   nLen := Len( cString )

   For nI := 1 To nLen
      cAscii += AllTrim( Str( Asc( SubStr( cString, nI, 1 ) ) ) ) + ;
         If( nI < nLen, ",", "" )
   Next

Return cAscii

//----------------------------------------------------------------------------//

METHOD PrinterStatus() CLASS TDosPrn

   Local nStatus

   If ::nLPTBase > 0
      #ifdef __CLIPPER__
      nStatus := InPortByte( ::nLPTBase + 1 )
      ::lPrnError  := ! lIsBit( nStatus, 4 )
      ::lPrnSelect :=   lIsBit( nStatus, 5 )
      ::lPaperOut  :=   lIsBit( nStatus, 6 )
      ::lDataAck   := ! lIsBit( nStatus, 7 )
      ::lPrnBusy   := ! lIsBit( nStatus, 8 )
      #else           // under 32 bits InPortByte() GPF's so this is the best we can do for the time being
      ::lPrnSelect := .T.
      #endif
   Endif

Return Self

//-----------------------------------------------

Static Function lIsBit( nValor, nPosBit )

   Local aBits := { 1, 2, 4, 8, 16, 32, 64, 128 }
   Local nBit, lBit := .F.

   If nPosBit >= 1 .and. nPosBit <= Len( aBits )
      For nBit := Len( aBits ) To 1 Step -1
         If nValor >= aBits[nBit]
            nValor -= aBits[nBit]
         Else
            aBits[nBit] := 0
         Endif
      Next
      lBit := aBits[nPosBit] > 0
   Endif

Return lBit

//----------------------------------------------------------------------------//
 
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby karinha » Wed Sep 22, 2021 12:38 am

Hola, intenta con la que uso.. Dudas, pregunte.

Code: Select all  Expand view

/*
ÚÄ Programa ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³   Aplication: Class TDosPrint                                            ³
³         File: TDOSPRN.PRG                                                ³
³       Author: Ignacio Ortiz de Z£¤iga Echeverr¡a                         ³
³          CIS: Ignacio Ortiz (Ignacio_Ortiz)                              ³
³     Internet: http://www.ozs.com                                         ³
³         Date: 09/13/96                                                   ³
³         Time: 20:20:07                                                   ³
³    Copyright: 1997 by Ortiz de Zu¤iga, S.L.                              ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

NOTES:

This peace of software is freeware and is not part of FiveWin.

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.

The use of the class is very easy and is very similar to the TPrinter class
of Fivewin, but we have not create any command to avoid the use of any
static vars.

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:

DATA:

 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

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 on page,
               or you try to print in a row that is before the current one,
               like it did happen with the SAY command
 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   ,;
     cText   )
 SayCmp()      The same as the method Say but prints in compressed mode and
               the row is updated accordly.

NOTE:

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

Enjoy it!

*/


/*
// Baixei de www.fivewin.com.br em 01/11/2002
// Modifiquei em 03/11/2002 - karinhannah@bol.com.br  By JoÆo.
// InclusÆo: Parte Modificada Por Ednaldo Rolim - edrol@pop.com.br
// Acrescentada a Parte Modificada Pelo Gilmer: www.fivewin.com.br
*/


#Include "FiveWin.Ch"
#Include "Fileio.Ch"

#Translate nTrim(<n>)  => AllTrim(Str(<n>,10,0))

#define PF_BUFLEN   2048

//----------------------------------------------------------------------------//

CLASS TDosPrn

     DATA LastError
     DATA cPort, cCompress, cNormal, cFormFeed, cBuffer
     DATA hDC, nRow, nCol, nLeftMargin, nTopMargin
     DATA lAnsiToOem, lCompress
     DATA lZeraBuffer // By Gilmer www.fivewin.com.br
     DATA ImpUSB // AS LOGICAL  By Diego@sysfar.com.br // Imprimir na USB

     DATA oWnd, oPagina                      // Ednaldo
     DATA nPage        AS NUMERIC            // Ednaldo

     //METHOD New(cPort) CONSTRUCTOR
     METHOD New(cPort, cVerUSB) CONSTRUCTOR   // By Diego da Sysfar

     METHOD End()

     // Antigo(Old)
     // METHOD StartPage()  VIRTUAL // NÆo Conta as P ginas
     // METHOD EndPage()

     // Novo (New)   // Conta as P ginas By Ednaldo Rolim
     METHOD StartPage()    INLINE ::ShowProc()           // Ednaldo

     METHOD EndPage()

     // METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) //velho
     METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5)   // novo

     METHOD SetCoors(nRow, nCol)

     METHOD NewLine()       INLINE (::cBuffer += CRLF ,;
                                    ::nRow++          ,;
                                    ::nCol    := 0     )

     METHOD Write(cText, lAToO) ;
            INLINE (IIF(lAtoO == NIL, lAtoO := .T.,),;
                    ::cBuffer += iif(lAtoO, AnsitoOem(cText), cText) ,;
                    ::nCol    += len(cText)                           )

     METHOD Say(nRow, nCol, cText, lAToO)

     METHOD SayCmp(nRow, nCol, cText)

     METHOD CharSay(nRow,nCol,cText) INLINE (IIf(::lCompress,;
                ::SayCmp(nRow,nCol,cText),;
                ::Say(nRow,nCol,cText)))

     METHOD ZeraBuffer() // By. Gilmer

     METHOD PrintFile(cFile)

     METHOD ShowProc()          // Ednaldo

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cPort, lFile, lCompress, cVerUSB ) CLASS TDosPrn

     DEFAULT cPort   := "LPT1", ;
             cVerUSB := .F.,    ;
             lFile   := .T.   , ;
             lCompress := .F.

     cPort := Upper(cPort)

     /* // Copiei de DOSPRINT.PRG
     [EPSON]
     Normal=18
     Bold=27,18,27,69
     Medium=27,70,27,58
     Compress=15
     Large=27,69,27,18,27,14
     Tiny=27,70,27,83,0,27,49,18,15
     NoTiny=27,70,27,84,27,50
     FormFeed=12
     Length=27,67,0

     [OKIDATA]
     Normal=27,70,27,84,27,50,27,15,18
     Bold=27,18,27,69
     Medium=27,70,27,58
     Compress=27,70,27,84,27,15
     Large=27,69,27,18,27,14
     Tiny=27,70,27,83,0,27,49,18,15
     NoTiny=27,70,27,84,27,50
     Image=27,76
     Header=
     Footer=
     Jump=216
     FormFeed=12
     Length=27,67,0
     */


     ::ImpUSB      := .F.
     ::cCompress   := "15"
     ::cNormal     := "18"
     ::cFormFeed   := "  "  // 12  //Pulo de P gina
     ::cBuffer     := ""
     ::nLeftMargin := 0
     ::nTopMargin  := 0
     ::nRow        := 0
     ::nCol        := 0
     ::lAnsiToOem  := .T.
     ::cPort       := cPort + iif(!"." $ cPort, ".PRN", "")

     If cVerUSB .and. upper( PrnGetPort( ) )="USB"
        //::cPort := DirTempdoWindows()+"\usb.imp"
         ::cPort       := cPort + iif(!"." $ cPort, ".IMP", "")
     Endif

     ::hDC         := fCreate(::cPort)
     ::LastError   := 0
     // By. Gilmer  // .F. Pula P gina, .T. NÆo Pula a P gina (Cupom Fiscal)
     ::lZeraBuffer := .F.

     IF ::hDC < 0
          ::LastError := fError()
     ENDIF

     ::nPage := 1                  // Ednaldo
     ::ShowProc()                  // Ednaldo

RETURN Self


//----------------------------------------------------------------------------//

METHOD End() CLASS TDosPrn

     IF !empty(::nRow+::nCol)
          ::EndPage()
     ENDIF

     ::LastError := 0

     IF !fClose(::hDC)
          ::LastError := fError()
     ENDIF

     CursorArrow()

     if ::oWnd != Nil                    // Ednaldo
        ::oWnd:End()                     // Ednaldo
     endif                               // Ednaldo

RETURN NIL

//----------------------------------------------------------------------------//

METHOD EndPage() CLASS TDosPrn

     LOCAL nFor, nLen, nSec
     LOCAL lError

     If !::lZeraBuffer  // By Gilmer
        ::Command(::cFormFeed)
     End

     ::LastError := 0

     IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
          ::LastError := fError()
     ENDIF

     ::cBuffer := ""
     ::nRow    := 0
     ::nCol    := 0

RETURN NIL

//----------------------------------------------------------------------------//

//METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) CLASS TDosPrn // Velho
METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5) CLASS TDosPrn  // Novo

     LOCAL cCommand, cToken, cString
     LOCAL nToken

     //cString  := cValToChar(xPar1) // Velho

     cString  := cStr1   // Novo

/* // Velho
     IF xPar2 != NIL
          cString += ","+cValToChar(xPar2)
     ENDIF
*/


     IF cStr2 != NIL
          cString += ","+cStr2
     ENDIF

/*   // Velho
     IF xPar3 != NIL
          cString += ","+cValToChar(xPar3)
     ENDIF
*/


     IF cStr3 != NIL
          cString += ","+cStr3
     ENDIF

/*   // Velho
     IF xPar4 != NIL
          cString += ","+cValToChar(xPar4)
     ENDIF
*/


     IF cStr4 != NIL
          cString += ","+cStr4
     ENDIF

/*   // Velho
     IF xPar5 != NIL
          cString += ","+cValToChar(xPar5)
     ENDIF
*/


     IF cStr5 != NIL
          cString += ","+cStr5
     ENDIF

     cCommand := ""
     nToken   := 1

     DO WHILE !Empty(cToken := StrToken(cString, nToken++, ","))
          cCommand += Chr(Val(cToken))
     ENDDO

     ::cBuffer += cCommand

RETURN NIL

//----------------------------------------------------------------------------//

METHOD SetCoors(nRow, nCol) CLASS TDosPrn

     nRow += ::nTopMargin
     nCol += ::nLeftMargin

     IF ::nRow > nRow
          ::EndPage()
          ::nPage++                          // Ednaldo
          ::StartPage()
     ENDIF

     /*   // do Site
     IF ::nRow > nRow
          ::EndPage()
          ::StartPage()
     ENDIF
     */


     // Tava Aqui

     /*   // do Site
     IF nRow == ::nRow  .AND. nCol < ::nCol
          ::EndPage()
          ::StartPage()
     ENDIF
     */


     DO WHILE ::nRow < nRow
          ::NewLine()
     ENDDO

     IF nCol > ::nCol
          ::Write(Space(nCol-::nCol))
     ENDIF

     // Para Imprimir Primeiro na coluna desejada exemplo 1§ na Coluna 50
     // Depois na coluna 05... By NetSpeed Inverte-se a Ordem da Cabe‡a de
     // ImpressÆo, Come‡ando do Fim Para o Inicio...
     If nRow == ::nRow .and. nCol < ::nCol
         ::Write(Chr(13))  // NetSpeed
     Endif

     // Aqui Inicia da Coluna 1 em diante, nÆo faz como a anterior.
     // Ou Seja do Inicio Para o Fim da Cabe‡a de ImpressÆo, o Que ‚ Normal.
     IF nRow == ::nRow  .AND. nCol < ::nCol
          ::EndPage()
          ::nPage++                          // Ednaldo
          ::StartPage()
     ENDIF

     // By. Gilmer
     If Len(::cBuffer)>=7928
        ::ZeraBuffer()
     Endif

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Say(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     IF VALTYPE( cText ) = "D"
        cText := DTOC( cText )
     ENDIF

     IF VALTYPE( cText ) = "N"
        cText := STR( cText )
     ENDIF

     ::SetCoors(nRow, nCol)

     ::Write(cText, lAToO)

RETURN NIL

//----------------------------------------------------------------------------//

METHOD SayCmp(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     ::Command(::cCompress)
     ::SetCoors(nRow, nCol)
     ::cBuffer += iif(lAToO, AnsitoOem(cText), cText)
     ::nCol    += Int(len(cText))
     * by Digao     ::nCol    += Int(len(cText)/1.7+.5)
     ::Command(::cNormal)

RETURN NIL

//----------------------------------------------------------------------------//

METHOD ZeraBuffer() CLASS TDosPrn

    /* // Em Ingles
    ::LastError := 0

    If ::lZeraBuffer
        IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
                ::LastError := fError()
        ENDIF
        ::cBuffer := ""
    Endif
    */


    // Em Clipper Puro Como ‚!
    Self:LastError := 0

    If Self:lZeraBuffer
        IF fWrite(Self:hDC, Self:cBuffer) < len(Self:cBuffer)
             Self:LastError := fError()
        ENDIF
        Self:cBuffer := ""
    Endif

RETURN NIL

//----------------------------------------------------------------------------//

FUNCTION WorkSheet(cPort)

     LOCAL oPrn
     LOCAL cLine
     LOCAL nFor

     cLine := ""

     FOR nFor := 0 TO 7
          cLine += Str(nFor,1)+Replicate(".",9)
     NEXT

     cLine := Substr(cLine,3)

     oPrn := TDosPrn():New(cPort)

     oPrn:StartPage()

     //alterei em 29/03/2004, Pois Com o Five 2.4, Pulo de P gina estava errado
     FOR nFor := 0 TO  56 //65
          oPrn:Say(nFor,0,StrZero(nFor,2)+cLine)
     NEXT

     oPrn:EndPage()

     oPrn:End()

RETURN NIL

//----------------------------------------------------------------------------//

METHOD PrintFile(cFile) CLASS TDosPrn

     LOCAL hFile
     LOCAL nRead
     LOCAL cBuffer

     hFile := FOpen(cFile, FO_READ)

     IF hFile < 0
          RETURN .F.
     ENDIF

     cBuffer := Space(PF_BUFLEN)

     DO
          nRead := fRead(hFile, @cBuffer, PF_BUFLEN)

          IF fWrite(::hDC, Left(cBuffer, nRead)) < nRead
               ::LastError := fError()
               fClose(hFile)
               RETURN .F.
          ENDIF
     UNTIL nRead == PF_BUFLEN

     fClose(hFile)

RETURN .T.

//----------------------------------------------------------------------------//
// Visualiza Processo de impressao                 // Ednaldo
//----------------------------------------------------------------------------//
METHOD ShowProc() CLASS TDosPrn                  

     IF ::oWnd = Nil
                   
*        DEFINE DIALOG ::oWnd TITLE "Imprimindo ..."  ;
*               FROM  230, 217 TO 360, 575 PIXEL ;
*               COLORS CLR_BLACK, nRGB(193,205,205)
*        
*        @ 10, 08 TO 40, 172 OF ::oWnd PIXEL
*
*        @ 1.4, 2 ICON NAME "PRINT.ICO" OF ::oWnd
*        
*        @ 25, 35  SAY "Imprimindo Página :"  ;
*                  PIXEL OF ::oWnd SIZE 70, 12  RIGHT
*
*        @ 25, 107 SAY ::oPagina VAR ::nPage  ;
*                  PIXEL OF ::oWnd UPDATE SIZE 15, 12 RIGHT
*
*        @ 47, 60 BUTTON "Aguarde..." SIZE 60, 12 ;
*                 PIXEL  OF ::oWnd  ACTION .t.
*
*        ::oWnd:bPainted := {|| iif(::nPage>0, ::oPagina:Refresh(), )}
*
*        ACTIVATE DIALOG ::oWnd CENTER NOWAIT
*
*        EndDialog()
        ResAllFree()

        CursorWait()
        SysRefresh()

     ELSE

        ::oWnd:BeginPaint()
        ::oWnd:Paint()
        ::oWnd:EndPaint()

     ENDIF

RETURN NIL

// Fim do Programa.
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Imprimir en rollo y matriz de punto

Postby karinha » Wed Sep 22, 2021 12:42 am

Ejemplo de uso general...

Code: Select all  Expand view

/*
USB com TDOSPRN.PRG

Enla cabecera de mi rutina de impresión hice esto:

cPorta := PrnGetPort()

cPrinter := PrinterPortToName( cPorta )

if empty(cPrinter)
   cPrinter := PrinterPortToName( "USB002" )
   if empty(cPrinter)
      cPrinter := PrinterPortToName( "USB001" )
   endif
endif
 

Despues empiezo la impresión, preo creando un archivo:


oPrin := TDosPrn():New("minuta.txt")
oPrin:StartPage()
...
...
 

Y en el fin de la rutina hago esto:


...
...
oPrin:EndPage()
oPrin:End()


PrintFileRaw( cPrinter, TrueName("MINUTA.TXT"), "Impressão de Vendas" )
*/


// ----------------------------------------------------------------------------

//----- Definicao de comando SAY para TdosPrn ---------------------------------
//

#xcommand @ <nRow>, <nCol> SAY <cText> OF <oPrinter> => <oPrinter>:Say(<nRow>, <nCol>, <cText> )

//-------------------------------------------------------------------------//
// Imprime os Cupons Nao Fiscal da Pizzaria/Restaurante
//-------------------------------------------------------------------------//

STATIC FUNCTION IMPRIMIR_CUPOM( nKey, aGetVenda, oLbx, oDlgVendas, DbClientes,;
                                                       DbEstoque,  DbPedidos )

    FIELD QTD_VENDEU, DESCRICAO, VLUNITARIO, TOTITEM, TOTPEDIDO
    FIELD MENSAG1, MENSAG2, MENSAG3, MENSAG4, MENSAG5

    LOCAL nLinha, nPag, oPrn, Conta, Pula, DbMensag

    MEMVAR XNUMPEDIDO,   nNumeroTel,   cCodClien,   cNomeClien,   cEndClien,  ;
           cNomeProduto, nQuantidade,  nValorProd,  nValorCompra, oSayCxLivre,;
           XCGCCLI,      nQtdeEstoque, nCodigoProd
    MEMVAR nDinheiro,    nCheque,     nChequePre,  nTickets,     nCartaoCred,;
           nCartaoDebi,  nContraVale, nTaxaEntreg, nValorTroco,  nSomaSubTot,;
           XTROCOCLI,    Valor_Pago,  nValor_Pago, oSayEmpresa

    //-> Nome Fantasia da Empresa - Est  em EMPRESA.DBF
    PUBLIC XDA, XCAIXA, XCODVEND, XNOMEEMP, XFANTASIA, XIMPQTDECOP, ;
           XPULARLINHA

    nLinha      := 0
    nPag        := 1

    IF XIMPQTDECOP <= 0
       XIMPQTDECOP := 1
    ENDIF

    //-> Mensagens do Rodape
    IF NETUSE( "MENSAGEM", .T. )
       DATABASE DbMensag
       DbMensag:Load()        //-> Temporario = a FP_PROV.DBF
       DbMensag:SetBuffer( .T. )
    ENDIF

    SELECT ( DbPedidos:cAlias )
    DbPedidos:SetOrder( 1 )
    GO TOP

    // Para Rede de Computadores
    // oPrn:New("\\seuterminal\suaimpressora\LPT1")
    oPrn:= TDosPrn():New( "CUPOM.TXT" ) // para ir para um arquivo .txt
    // oPrn:= TDosPrn():New()        // para ir para impressora em definitivo
    // oPrn := TDosPrn():New("lpt1") // para ir para impressora em definitivo
    // Este Comando, Liga a Impressora. NÆo Tirar Nunca
    oPrn:StartPage() // da Start(inicializa) na p gina.
    oPrn:lZeraBuffer := .T.             // Inibe o Pulo da P gina

    //-> Inicia a Impressao - Cabe‡alho do Cupom
    //-> Modo Draft
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"          OF oPrn

    @ nLinha, 00 SAY SUBST( XNOMEEMP, 1, 23 )                  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                 OF oPrn
    nLinha := nLinha + 1

    //-> Modo Condensado
    @ nLinha, 00 SAY CHR(15)+"HORA: " + TIME() + " - " + ;
                            + DTOC(XDA)                        OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY OemToAnsi("PEDIDO N§: " ) + ;
                     ALLTRIM(STRZERO( XNUMPEDIDO ) )           OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "FONE..: " + nNumeroTel                   OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY SUBSTR( cNomeClien, 1, 40 )               OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY SUBSTR( cEndClien, 1, 40 )                OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY REPLICATE("-",38)                         OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "Cod   Qtde   Descricao  Unit     Valor"  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY REPLICATE("-",38)                         OF oPrn
    nLinha := nLinha + 1

    //-> Imprime o Pedido
    WHILE !EOF()

       SYSREFRESH()

       IF EOF()
          EXIT
       ENDIF

       @ nLinha, 00 SAY ( DbPedidos:cAlias )->CODIGO          OF oPrn
       nLinha := nLinha + 1

       @ nLinha, 00 SAY ( ALLTRIM( STR( QTD_VENDEU ) ) ) +[ - ]+ ;
                        ( SUBSTR( DESCRICAO, 01, 17 ) )  OF oPrn

       nLinha := nLinha + 1

       @ nLinha, 00 SAY ( SUBSTR( DESCRICAO, 18, 35 ) )            +  ;
                          TRANSFORM( VLUNITARIO, "@E  99,999.99" ) +  ;
                          TRANSFORM( TOTITEM,    "@E 999,999.99" ) OF oPrn

       nLinha := nLinha + 1

       DBSKIP()

    ENDDO

    //-> Total do Pedido
    IF EOF() .OR. TOTPEDIDO <= 0
       SKIP(-1)
    ENDIF

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    IF nDinheiro    > 0
       @ nLinha, 00 SAY "EM DINHEIRO:   " + ;
                    TRANSFORM( nDinheiro, "@E 999,999.99" )    OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCheque      > 0
       @ nLinha, 00 SAY "EM CHEQUE:     " + ;
                    TRANSFORM( nCheque, "@E 999,999.99" )      OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nChequePre   > 0
       @ nLinha, 00 SAY "EM CHEQUE PRE: " + ;
                    TRANSFORM( nChequePre, "@E 999,999.99" )   OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nTickets     > 0
       @ nLinha, 00 SAY "EM TICKETS:    " + ;
                    TRANSFORM( nTickets, "@E 999,999.99" )     OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCartaoCred  > 0
       @ nLinha, 00 SAY "EM C. CREDITO: " + ;
                    TRANSFORM( nCartaoCred, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCartaoDebi  > 0
       @ nLinha, 00 SAY "EM C. DEBITO:  " + ;
                    TRANSFORM( nCartaoDebi, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nContraVale  > 0
       @ nLinha, 00 SAY "EM C. VALE:    " + ;
                    TRANSFORM( nContraVale, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    //-> Fechou o Cupom
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"  + ;
                     "TOTAL: "                         + ;
                     TRANSFORM( TOTPEDIDO, "@E 9,999,999.99" )  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+"TROCO:    " + ;
                 TRANSFORM( XTROCOCLI, "@E 999,999.99" )        OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "CAIXA: " + STRZERO( XCAIXA, 3 ) + [ - ] + ;
                     "OPERADOR: " + XCODVEND                    OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    SELECT ( DbMensag:cAlias )
    GO TOP

    WHILE !EOF()

       SYSREFRESH()

       IF EOF()
          EXIT
       ENDIF

       IF (MENSAG1 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG1  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG2 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG2  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG3 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG3  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG4 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG4  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG5 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG5  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)              OF oPrn
       nLinha := nLinha + 1

       DBSKIP()

    ENDDO

    //-> Pulos do Cupom
    FOR PULA = 1 TO XPULARLINHA
       @ nLinha, 00 SAY "."                                    OF oPrn
       nLinha := nLinha + 1
    NEXT PULA

    //-> Modo Draft
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"           OF oPrn

    oPrn:EndPage()
    oPrn:End()

    //--- imprime no spool do windows, liberando o micro para trabalhar.
    ImpSpool( "CUPOM.TXT",, .T. ) // esta em DBMANT.PRG impressora USB/matricial
    //--- opcionamente pode-se apagar o arquivo passando .t. no 3o. parametro.

    DbMensag:Close()

    SELECT ( DbPedidos:cAlias )
    DbPedidos:SetOrder( 1 )
    DbPedidos:Gotop()

RETURN NIL

// Maravilhoso Ednaldo Cabra Bom!!!
//----------------------------------------------------------------------------//
// Funcao    : ImpSpool( cFileTxt, cPorta, lErase )
// Autor     : Ednaldo Rolim (edrol@pop.com.br)
// Descricao : Envia um arquivo TXT criado pela TDosPrn para uma
//             porta de Impressora.
//----------------------------------------------------------------------------//
FUNCTION ImpSpool( cFileTxt, cPorta, lErase )

    LOCAL CPRINTER

    //para capturar antes da impressão
    //cPorta := PrnGetPorta()
    //WinExec( cPorta )
    //depois da impressão
    //WinExex( "Net Use Lpt1: \Delete" )
    //Ficou mais facil e simples do que criar as portas na Classe TDosPrn
    //cPorta := If( cPorta == nil, Alltrim( PrnGetPort() ), cPorta ) ; lErase := If( lErase == nil, .T., lErase );

    //cPorta := PrnGetPort()
    Default cPorta := Alltrim( PrnGetPort() ), lErase:= .t.

    cPrinter := PrinterPortToName( cPorta )

    IF EMPTY( cPrinter )

       cPrinter := PrinterPortToName( "USB002" )

       IF EMPTY(cPrinter)

          cPrinter := PrinterPortToName( "USB001" )

       ENDIF

    ENDIF
   
    IF .NOT. FILE( cFileTxt )

       MsgInfo( OemToAnsi( "NÇO ACHEI O ARQUIVO MODO TEXTO PARA IMPRIMIR NA MATRICIAL" ), ;
                OemToAnsi( "NÇO ACHEI O ARQUIVO MODO TEXTO PARA IMPRIMIR NA MATRICIAL" ) )

       RETURN( .F. )

    ENDIF

    IF .NOT. EMPTY( cPrinter )  // TEM USB

       PrintFileRaw( cPrinter, TrueName( "CUPOM.TXT" ), "Impressão de Vendas" )

    ELSEIF LEN( cPorta ) <= 5 .and. Left( Upper(cPorta), 4 ) = "LPT1"

       //--- Spool Local - Matricial em LPT1
       cPorta:= "PRN"

       WAITRUN("COMMAND.COM /C COPY /B " + cFileTxt + " " + cPorta, 0 )

    ELSE

       //--- Spool Remoto - Matricial em LPT1
       WAITRUN("COMMAND.COM /C COPY /B " + cFileTxt + " " + cPorta, 0 )

    ENDIF

    IF lErase // Vem .T. da tela de vendas
       FERASE( cFileTxt )
    ENDIF

RETURN( .T. )
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 1:19 am

Hola Joao.

Gracias ¡

Voy a probar y te comento el resultado.
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby cmsoft » Wed Sep 22, 2021 11:57 am

Hola Jose, la clase Tprint viene con Fivewin, que version estas usando?
Code: Select all  Expand view

#include "Print.ch"

Fijate si el archivo print.ch en fwh\include tiene estas caracteristicas al menos:
Code: Select all  Expand view
#ifndef _PRINT_CH
#define _PRINT_CH

//----------------------------------------------------------------------------//
// Printer

#xcommand PRINT [ <oPrint> ] ;
             [ <name: NAME, TITLE, DOC> <cDocument> ] ;
             [ <user: FROM USER> ] ;
             [ <prvw: PREVIEW> [<lmodal: MODAL>] ] ;
             [ TO  <xModel> ] ;
             [ <sele: SELECTION> ] ;
             [ FILE <cFile> ] ;
       => ;
      [ <oPrint> := ] PrintBegin( [<cDocument>], <.user.>, <.prvw.>, <xModel>, ;
                                  <.lmodal.>, <.sele.>, <cFile> )

#xcommand PRINTER [ <oPrint> ] ;
             [ <name: NAME, TITLE, DOC> <cDocument> ] ;
             [ <user: FROM USER> ] ;
             [ <prvw: PREVIEW> [<lmodal: MODAL>] ] ;
             [ TO  <xModel> ] ;
             [ <sele: SELECTION> ] ;
             [ FILE <cFile> ] ;
       => ;
      [ <oPrint> := ] PrintBegin( [<cDocument>], <.user.>, <.prvw.>, <xModel>, ;
                                  <.lmodal.>, <.sele.>, <cFile> )

#xcommand PAGE => PageBegin()

#xcommand ENDPAGE => PageEnd()

#xcommand ENDPRINT   => PrintEnd()
#xcommand ENDPRINTER => PrintEnd()

#xcommand @ <nRow>, <nCol> PRINT TO <prn> TEXT <cText> ;
      [SIZE <nWidth> [,<nHeight>] ] ;
      [<unit: PIXEL,MM,CM,INCHES>] ;
      [FONT <fnt>] ;
      [ALIGN <aln>] ;
      [COLOR <nTxt> [,<nBck> ] ] ;
      [LASTROW <lrow>] ;
   => ;
      [<lrow> := ] <prn>:SayText( <nRow>, <nCol>, <cText>, [<nWidth>], [<nHeight>], ;
            [<fnt>], [<aln>], [<nTxt>], [<nBck>], [<(unit)>] )


#xcommand @ <nRow>, <nCol> PRINT TO <prn> IMAGE <img> ;
      [SIZE <nWidth> [,<nHeight>] ] ;
      [<unit: PIXEL,MM,CM,INCHES>] ;
      [<lStr: STRETCH>] ;
      [ ALPHALEVEL <nAlpha>] ;
      [<lNoTrn: NOTRANSPARENT>] ;
      [<lGray: GRAY> ] ;
      [LASTROW <lrow>] ;
   => ;
      [<lrow> := ] <prn>:PrintImage( <nRow>, <nCol>, <img>, [<nWidth>], [<nHeight>], ;
            [<.lStr.>], [<nAlpha>], [!<.lNoTrn.>], [<.lGray.>], [<(unit)>] )


//----------------------------------------------------------------------------//

#endif
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 1:35 pm

Hola Cesar, saludos

Cual es el nombre correcto de la clase? la busque como tprinter en la carpeta source y no esta, igualmente aplique tu código y salieron muchos errores, asumí que me falta la clase. a lo mejor tiene otro nombre, pero igual me arrojó errores propios de la clase. Voy a probar con esto que me estas pasando y te comento

Tengo FW17.01 y xHarbour
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby karinha » Wed Sep 22, 2021 2:14 pm

Creo que esta version no sirve para el que intentas.

C:\FWH1701\SOURCE\CLASSES

Code: Select all  Expand view


31/01/2017  11:19            40.239 printer.prg
               1 arquivo(s)         40.239 bytes
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 2:24 pm

Listo amigos...

Gracias a Todos...

Cesar, solucionado con tprinter... solo me faltaba el PRINTER.CH en el scrip de compilacion...

Un abrazo hermanos, agradecido de uds una vez mas.
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Imprimir en rollo y matriz de punto

Postby karinha » Wed Sep 22, 2021 3:15 pm

JoseAlvarez wrote:Listo amigos...

Gracias a Todos...

Cesar, solucionado con tprinter... solo me faltaba el PRINTER.CH en el scrip de compilacion...

Un abrazo hermanos, agradecido de uds una vez mas.


José, podrias poner un ejemplo simples para el futuro? Asi todos pueden saber.

Muchas gracias.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Imprimir en rollo y matriz de punto

Postby cmsoft » Wed Sep 22, 2021 4:08 pm

Me alegro Jose que lo hayas solucionado.
Saludos!
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Imprimir en rollo y matriz de punto

Postby JoseAlvarez » Wed Sep 22, 2021 7:22 pm

karinha wrote:
JoseAlvarez wrote:Listo amigos...

Gracias a Todos...

Cesar, solucionado con tprinter... solo me faltaba el PRINTER.CH en el scrip de compilacion...

Un abrazo hermanos, agradecido de uds una vez mas.


José, podrias poner un ejemplo simples para el futuro? Asi todos pueden saber.

Muchas gracias.

Regards, saludos.


CLARO QUE SI ! en cuanto termine la funcion de impresion, limpie y ordene el codigo, lo colocare aca.

Aprovecho para preguntar, hay alguna manera de evitar el salto de pagina al finalizar? se desperdicia mucho papel cuando es un rollo.
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests