FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour La clase tprinter, consulta [RESUELTO]
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
La clase tprinter, consulta [RESUELTO]
Posted: Wed Apr 10, 2024 04:49 PM
Hace mucho que no uso esta clase, pero tengo que crear unos recibos a partir de un array

Este es el código que escribí para ello:
Code (fw): Select all Collapse
FUNCTION ImprimoRecibos( aDatos )
    local oPrn, oFonN, i:=0, j:=0, k:=0, nRowStep, nColStep
    
    DEFINE FONT oFonN NAME "Century Gothic" SIZE 0,12 OF oprn
       
    PRINT oPrn DOC "recibos" FROM USER PREVIEW

        oPrn:SetPage(9)                         // A4
        oPrn:SetPortrait()                      //Vertical

        nRowStep = oPrn:nVertRes() / 60         // 60 filas
        nColStep = oPrn:nHorzRes() / 80         // 80 columnas
        PAGE
        FOR i = 1 to Len( aDatos )
                oPrn:CmSay( j+ 1*nRowStep, 3*nColStep, "No.  " + Alltrim( Str( aDatos[i,1] ) ), oFonN )
                oPrn:CmSay( j+ 2*nRowStep, 3*nColStep, "Fecha: " + Dtoc( aDatos[i,2] ), oFonN )
                oPrn:CmSay( j+ 3*nRowStep, 3*nColStep, "Importe  U$:" + Transform( aDatos[i,9], "999,999,999.99" ) , oFonN )
                oPrn:CmSay( j+ 4*nRowStep, 3*nColStep, "Recibí de " + Alltrim( aDatos[i,3] ) + ", la suma de Pesos Uruguayos:", oFonN )
                oPrn:CmSay( j+ 5*nRowStep, 3*nColStep, aDatos[i,10], oFonN )
                oPrn:CmSay( j+ 6*nRowStep, 3*nColStep, "Por concepto de: " + aDatos[i,4], oFonN )
                oPrn:CmSay( j+ 7*nRowStep, 3*nColStep, "Montevideo, fecha ", oFonN )
                oPrn:CmSay( j+10*nRowStep, 3*nColStep, "Firma:  __________________________" ,oFontN )
                oPrn:CmSay( j+11*nRowStep, 3*nColStep, "       " + Alltrim( aDatos[i,7] ) + ", " + Alltrim( aDatos[i,8] ) , oFonN )
                oPrn:Line(  j+13*nRowStep, 1*nColStep, j+13*nRowStep, 79*nColStep )
                k++
                j+= 15*nRowStep 
            IF k > 4
                ENDPAGE 
                k:=0
                j:=0
                IF i<=Len( aDatos )
                    PAGE
                ENDIF
            ENDIF
            
        NEXT i

    ENDPRINT

RETURN nil
Me ocurre que al mandar a imprimir solo me imprime las líneas no los textos y variables...
No me he dado cuenta donde está el error, si alguien pudiera quizas ayudarme con una guía, lo agradeceré profundamente.
Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: La clase tprinter, consulta
Posted: Wed Apr 10, 2024 05:37 PM
Code (fw): Select all Collapse
FUNCTION ImprimoRecibos( aDatos )

   LOCAL oPrn, oFonN, i := 0, j := 0, k := 0, nRowStep, nColStep

   PRINT oPrn DOC "recibos" FROM USER PREVIEW

   DEFINE FONT oFonN NAME "Century Gothic" SIZE 0, 12 OF oPrn // AQUI

   oPrn:SetPage( 9 )                         // A4
   oPrn:SetPortrait()                      // Vertical

   nRowStep = oPrn:nVertRes() / 60         // 60 filas
   nColStep = oPrn:nHorzRes() / 80         // 80 columnas

   PAGE

      FOR i = 1 TO Len( aDatos )

         oPrn:CmSay( j + 1 * nRowStep, 3 * nColStep, "No.  " + AllTrim( Str( aDatos[ i, 1 ] ) ), oFonN )

         oPrn:CmSay( j + 2 * nRowStep, 3 * nColStep, "Fecha: " + DToC( aDatos[ i, 2 ] ), oFonN )

         oPrn:CmSay( j + 3 * nRowStep, 3 * nColStep, "Importe  U$:" + Transform( aDatos[ i, 9 ], "999,999,999.99" ), oFonN )

         oPrn:CmSay( j + 4 * nRowStep, 3 * nColStep, "Recibí de " + AllTrim( aDatos[ i, 3 ] ) + ", la suma de Pesos Uruguayos:", oFonN )

         oPrn:CmSay( j + 5 * nRowStep, 3 * nColStep, aDatos[ i, 10 ], oFonN )

         oPrn:CmSay( j + 6 * nRowStep, 3 * nColStep, "Por concepto de: " + aDatos[ i, 4 ], oFonN )

         oPrn:CmSay( j + 7 * nRowStep, 3 * nColStep, "Montevideo, fecha ", oFonN )

         oPrn:CmSay( j + 10 * nRowStep, 3 * nColStep, "Firma:  __________________________", oFontN )

         oPrn:CmSay( j + 11 * nRowStep, 3 * nColStep, "       " + AllTrim( aDatos[ i, 7 ] ) + ", " + AllTrim( aDatos[ i, 8 ] ), oFonN )

         oPrn:Line(  j + 13 * nRowStep, 1 * nColStep, j + 13 * nRowStep, 79 * nColStep )

         k++
         j += 15 * nRowStep

         IF k > 4

            ENDPAGE

            k := 0
            j := 0

            IF i <= Len( aDatos ) // ?? esto esta correcto?

               PAGE

            ENDIF

         ENDIF

      NEXT i

   ENDPAGE // AQUI

   ENDPRINT

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Re: La clase tprinter, consulta
Posted: Wed Apr 10, 2024 06:02 PM
Muchas gracias Karinha

Probé tu código y el resultado es el mismo, no entiendo porqué me imprime solo la línea que separa los recibos y no los textos.

Este es el código que ahora uso con tus modificaciones, el resultado es el mismo:
Code (fw): Select all Collapse
FUNCTION ImprimoRecibos( aDatos )

   LOCAL oPrn, oFonN, i := 0, j := 0, k := 0, nRowStep, nColStep

   PRINT oPrn DOC "recibos" FROM USER PREVIEW

   DEFINE FONT oFonN NAME "Century Gothic" SIZE 0, 12 OF oPrn // AQUI

   oPrn:SetPage( 9 )                         // A4
   oPrn:SetPortrait()                      // Vertical

   nRowStep = oPrn:nVertRes() / 60         // 60 filas
   nColStep = oPrn:nHorzRes() / 80         // 80 columnas

   PAGE

      FOR i = 1 TO Len( aDatos )

        oPrn:CmSay( j + 1 * nRowStep, 3 * nColStep, "No.  " + AllTrim( Str( aDatos[ i, 1 ] ) ), oFonN )

        oPrn:CmSay( j + 2 * nRowStep, 3 * nColStep, "Fecha: " + DToC( aDatos[ i, 2 ] ), oFonN )

        oPrn:CmSay( j + 3 * nRowStep, 3 * nColStep, "Importe  U$:" + Transform( aDatos[ i, 9 ], "999,999,999.99" ), oFonN )

        oPrn:CmSay( j + 4 * nRowStep, 3 * nColStep, "Recibí de " + AllTrim( aDatos[ i, 3 ] ) + ", la suma de Pesos Uruguayos:", oFonN )

        oPrn:CmSay( j + 5 * nRowStep, 3 * nColStep, aDatos[ i, 10 ], oFonN )

        oPrn:CmSay( j + 6 * nRowStep, 3 * nColStep, "Por concepto de: " + aDatos[ i, 4 ], oFonN )

        oPrn:CmSay( j + 7 * nRowStep, 3 * nColStep, "Montevideo, fecha ", oFonN )

        oPrn:CmSay( j + 10 * nRowStep, 3 * nColStep, "Firma:  __________________________", oFonN )

        oPrn:CmSay( j + 11 * nRowStep, 3 * nColStep, "       " + AllTrim( aDatos[ i, 7 ] ) + ", " + AllTrim( aDatos[ i, 8 ] ), oFonN )

        oPrn:Line(  j + 13 * nRowStep, 1 * nColStep, j + 13 * nRowStep, 79 * nColStep )

        k++
        j += 15 * nRowStep

        IF k > 3

            ENDPAGE

            k := 0
            j := 0

            IF i <= Len( aDatos )

               PAGE

            ENDIF

        ENDIF

      NEXT i

   ENDPAGE // AQUI

   ENDPRINT

RETURN NIL
Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: La clase tprinter, consulta
Posted: Wed Apr 10, 2024 09:37 PM
Mi estimado, aquí te envío un ejemplo:
Code (fw): Select all Collapse
Function ImpVerDocs(oCn, aDetVen, cNRuc, cNomb, cDirec, cDocumento, dFecha, cHora, cEstado, cAnulad, cGuiaRem, dFecGuia, nTMovi )
local oPrn, nLineas, oFontA, oFontE, oFontT, oFont0, nLin, nPag, nLinMax, nItens, nLen,nCont, cLInea, nCont2, nTotal, cTitle
DEFAULT nTMovi := 2

cTitle   := ""
cGuiaRem := ""
nLineas  := 0                 // tope
nTotal   := 0

PRINT oPrn NAME cDocumento PREVIEW

  If Empty( oPrn:hDC )
     Return(Nil)          // Printer was not installed or ready
  EndIf

  DEFINE FONT oFontA NAME "Arial" SIZE 0,-6 BOLD OF oPrn
  DEFINE FONT oFontE NAME "Arial" SIZE 0,-8 BOLD OF oPrn
  DEFINE FONT oFontT NAME "Courier New" SIZE 0,-8  OF oPrn
  DEFINE FONT oFont0  NAME "COURIER NEW" SIZE 0,8 OF oPrn
  oPrn:lPrvModal := .t.   // preview modal

  nLin    := 0.3
  nPag    := 1
  nLinMax := 27
  nItens  := 0

  nLen := LEN(aDetVen)

  PAGE
      FOR nCont := 1 TO nLen

       IF nLin = 0.3
         nLin := EncabezaP(oPrn, oFontE, cDocumento, nPag, nLin)

        oPrn:CmSay(nLin, 1, cDocumento + "  Fecha Documento : " + DTOC(dFecha) + IF(!EMPTY(cGuiaRem), "   Guia Remisión # " + cGuiaRem + "  Fecha: " + DTOC(dFecGuia),""), oFontE)
         nLin := nLin +0.3
        oPrn:CmSay(nLin, 1, If(nTMovi=1,"Proveedor","Cliente") + ": " + cNomb + "  RUC :"+ cNRuc, oFontE )
         nLin := nLin +0.3

        oPrn:CmSay(nLin, 1, "Dirección: " + cDirec + "  VEND: "+ cNomb, oFontE )
         nLin := nLin +0.3

        oPrn:CmSay(nLin,1,REPLICATE("-",160))
         nLin := nLin +0.25

        oPrn:CmSay(nLin, 1, "Producto", oFontA )
        oPrn:CmSay(nLin,13, "Unid.                       Cantidad       Costo Unitario            Precio Venta", oFontA )
         nLin := nLin + 0.2

        oPrn:CmSay(nLin,1,REPLICATE("-",160))   /*  Rayitas :) */
         nLin := nLin + 0.3
       ENDIF

       oPrn:CmSay(nLin,1, SUBSTR(PADR(aDetVen[nCont, 3],70),1,70), oFontT )  // ofont0

       oPrn:CmSay(nLin,13, aDetVen[nCont, 2] + " " + aDetVen[nCont, 1] + " " + STR(aDetVen[nCont, 4],10,2) + " " + aDetVen[nCont, 5], oFontT )  // ofont0

       nTotal := nTotal + VAL(aDetVen[nCont, 5])

       nLineas ++
       nLin := nLin + 0.3

       If nLineas >= 79  //nLin > 50                                // se paso del limite
         nLineas := 0
         nLin    := 0.3                               //  reiniciar contador
         nPag++
         oPrn:CmSay(27,1,"Fecha:"+DtoC(Date())+" Hora:"+Time(),oFont0)
         oPrn:EndPage()
         oPrn:StartPage()
       Endif

      NEXT nCont

      nlin ++

      cLinea := SPACE(86) + "Total :" + STR(nTotal,12,2)
      If nTotal > 0
        oPrn:CmSay(nLin,2, cLinea, oFontT )
      EndIf

      nLin := nLin + 0.3

      oPrn:CmSay(27,1,"Fecha:"+DtoC(Date())+" Hora:"+Time(),oFont0)

  ENDPAGE
  oFontA:End()
  oFontE:End()
  oFontT:End()
  oFont0:End()

ENDPRINT

Return(NIl)
Posts: 234
Joined: Tue Sep 01, 2009 07:55 AM
Re: La clase tprinter, consulta
Posted: Thu Apr 11, 2024 05:15 AM

Buenos días:

Prueba a cambiar el font por "Arial" a ver que resultados obtienes.

Un saludo

José Luis

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: La clase tprinter, consulta
Posted: Thu Apr 11, 2024 01:11 PM
Funciona bien con FONT Century.

Creo que el problema debe estar en el salto de línea. Muestra una imagen José, por favor.
Code (fw): Select all Collapse
// Printing an ascii file - \SAMPLES\TESTPRN5.PRG

#include "FiveWin.ch"

FUNCTION Main()

   LOCAL oPrn, cText := MemoRead( "testprn5.prg" )
   LOCAL oFont

   PRINT oPrn DOC "Recibos" FROM USER PREVIEW // PRINTER oPrn PREVIEW

      // DEFINE FONT oFont NAME "Courier New" SIZE 0, - 10 OF oPrn
      // DEFINE FONT oFont NAME "Century Gothic" SIZE 0, - 10 BOLD OF oPrn // Funciona bien
      DEFINE FONT oFont NAME "Century Regular" SIZE 0, - 10 BOLD OF oPrn // Bien mejor.

      PAGE

         @ 1, 1 PRINT TO oPrn TEXT cText SIZE 6, 9 INCHES FONT oFont

      ENDPAGE

   ENDPRINTER

   oFont:End()

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: La clase tprinter, consulta
Posted: Thu Apr 11, 2024 01:14 PM

Jose

El problema es que estas intentando mostrar los textos en CM y estas usando coordenadas de PIXELES

Cambia todos los CmSay por Say y te va a funcionar correctamente

Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Re: La clase tprinter, consulta
Posted: Thu Apr 11, 2024 07:41 PM
Jose
El problema es que estas intentando mostrar los textos en CM y estas usando coordenadas de PIXELES
Cambia todos los CmSay por Say y te va a funcionar correctamente
Estás en lo correcto cmsoft!!
Gracias a todos los que amablemente me mandaron ejemplos y ayudas,
Karinha, Willi, Groiss, cmsoft, que me ayudaron también a comprender el uso correcto de cmsay, y el uso de say.

Tal como lo sospechaba, se me había escapado la tortuga :D

Queda resuelto con mi gratitud para todos :D
Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"
Posts: 318
Joined: Fri Jan 14, 2022 08:37 AM
Re: La clase tprinter, consulta [RESUELTO]
Posted: Fri Apr 12, 2024 08:31 AM

Me pareciera a mi que nunca deben usarse coordenadas en pixeles, sino en cm/inchs para abstraer al programa de las diferentes resoluciones de las impresoras.

Asi pues usar CmSay() debería ser obligatorio

Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Re: La clase tprinter, consulta [RESUELTO]
Posted: Fri Apr 12, 2024 01:21 PM
paquitohm wrote:Me pareciera a mi que *nunca* deben usarse coordenadas en pixeles, sino en cm/inchs para abstraer al programa de las diferentes resoluciones de las impresoras.
Asi pues usar CmSay() debería ser obligatorio
Sabes, me parece que tienes toda la razón, sobre todo por la simplicidad, yo calculaba en el ejemplo filas y columnas a partir de la definición de la impresora , pero claro eso varía según la impresora.

Manejar cm. es la mejor opción

Gracias.
Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"

Continue the discussion