Página 2 de 2

IMPRESSÃO DE RELATÓRIOS

Enviado: 04 Dez 2018 11:12
por coiote64
Prezados:

Tem sido um grande aprendizado com todos vocês e suas explicações.

Nos tempos de Clipper, sempre usei o NODOSIMP para imprimir relatórios em impressora de rede ou USB.
Depois entrei no Harbour, continuo usando o NODOSIMP.

Aí, pensei...já que houve a evolução do Harbour, já existe algum comando direto que dispensasse o NODOSIMP para impressão em rede/USB?
Alguém sabe, por gentileza?
Caso sim, poste uma rotina-exemplo, por favor.

Muito obrigado.

IMPRESSÃO DE RELATÓRIOS

Enviado: 04 Dez 2018 13:43
por rubens
Boa tarde...

Dá uma olhada em
https://pctoledo.org/forum/viewto ... =4&t=18184

Rubens

IMPRESSÃO DE RELATÓRIOS

Enviado: 04 Dez 2018 13:51
por Paredes01
hola, en una Epson TMU220 usb

Código: Selecionar todos

//----------------------------
PROCEDURE PRINTWIN()

   cDevOut          := GetDefaultPrinter()
   oPrint           := Win32Prn():New(cDevOut)
   oPrint:Landscape := .F.
   oPrint:FormType  := 1  
   oPrint:Copies    := 1
   if !oPrint:Create()
      Alert("Cannot Create Printer")
      BREAK
   End if
   oPrint:SetFont('Lucida Console',9,{3,-50}, 0, .F., .F.)
   oPrint:leftMargin :=  05
   oPrint:rightMargin:= 200 
   oPrint:StartDoc()

   LIN   = 0
   NTOT  = 0
   PAG   = 0

   DbSelectar("Det_mov")
   If DBSeek(cfolio1)
      DO WHILE cfolio1=det_mov->folio .and. !Det_mov->(Eof())
         TITULOWIN()
         LIN=1
         
         oPrint:SetPrc(oPrint:Prow()+1,  0 )
         oPrint:Textout(Transf(det_mov->cant,"99,999.999"), .F. )

         oPrint:SetPrc(oPrint:Prow()  , 11 )
         oPrint:Textout(Transf(det_mov->costo_u,"99,999.999"), .F. )

         oPrint:SetPrc(oPrint:Prow()  , 25 )
         oPrint:Textout(Transf( (det_mov->cant*det_mov->costo_u), "99,999.999"), .F. )

         NTOT+= (det_mov->cant*det_mov->costo_u)

         DbSelectar("Articulo")
         DBSetOrder(1)
         nombre:=space(20)
         If DBSeek(AllTrim(det_mov->id_produc))
            nombre:=articulo->nom
            
            oPrint:SetPrc(oPrint:Prow()+1,  0 )
            oPrint:Textout(Transf(det_mov->cant, "99,999.999"), .F. )

            oPrint:SetPrc(oPrint:Prow(),  11 )
            oPrint:Textout(Transf(articulo->precio,"99,999.999"), .F. )

            oPrint:SetPrc(oPrint:Prow(),  25 )
            oPrint:Textout(Transf( (det_mov->cant*articulo->precio),"99,999.999"), .F. )

            DBSetOrder(2)
            If DBSeek(AllTrim(det_mov->id_produc))
               Do while det_mov->id_produc =  articulo->liga                
                  
		  oPrint:SetPrc(oPrint:Prow()+1,  0 )
                  oPrint:Textout(Transf(det_mov->cant, "99,999.999"), .F. )

                  oPrint:SetPrc(oPrint:Prow(),  11 )
                  oPrint:Textout(Transf(articulo->precio, "99,999.999"), .F. )

                  oPrint:SetPrc(oPrint:Prow(),  25 )
                  oPrint:Textout(Transf((det_mov->cant*articulo->precio) , "99,999.999"), .F. )

                  DBSkip()
               Enddo
            Endif           
            
	    oPrint:SetPrc(oPrint:Prow()+1,  0 )
            oPrint:Textout(det_mov->id_produc, .F. )

            oPrint:SetPrc(oPrint:Prow(),  10 )
            oPrint:Textout(substr(nombre,1,35), .F. )

         Else
           
            oPrint:SetPrc(oPrint:Prow()+1,  0 )
            oPrint:Textout("CLAVE NO ENCONTRADA", .F. )
         Endif

         DbSelectar("Det_mov")
         DBSkip()
      ENDDO
 
      oPrint:SetPrc(oPrint:Prow()+1,  0 )
      oPrint:Textout(REPLICATE("-",40), .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 10 )
      oPrint:Textout("TOTAL:", .F. )

      oPrint:SetPrc(oPrint:Prow(), 24 )
      oPrint:Textout(Transf(NTOT,"999,999.999"), .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout("   ", .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout(ENC_mov->CONCEP1, .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout(ENC_mov->CONCEP2, .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout(ENC_mov->CONCEP3, .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout("   ", .F. )

      oPrint:SetPrc(oPrint:Prow()+1, 0 )
      oPrint:Textout("REALIZO: "+ENC_MOV->USER, .F. )

   ELSE
      
      oPrint:SetPrc(oPrint:Prow(1), 1 )
      oPrint:Textout("NO ENCONTRE NADA" , .F. )
   ENDIF
   oPrint:EndDoc(.F.)
   oPrint:Destroy()
RETURN



//---------------------
PROCEDURE TITULOWIN()
   Dbselectar("Enc_mov")
   IF DBSEEK(CFOLIO1)
      IF LIN = 0
         PAG++
         oPrint:SetPrc(0, 0)

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout(cNOM_EMP,.F.)

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout(cSUC_EMP,.F.)

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout("REIMPRESION DE MOVIMIENTOS",.F.)

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout("FECHA DE IMP: " + DTOC(DATE()), .F. )

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout("FECHA DEL MOVTO: " + DTOC(ENC_MOV->FECHA) , .F. )

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout("CONCEPTO: " + SUBSTR(ENC_MOV->DE_CONCEP,1,32), .F. )

         oPrint:SetPrc(oPrint:Prow()+1, 0 )
         oPrint:Textout("FOLIO: " + + CFOLIO1, .F. )

         oPrint:SetPrc(oPrint:Prow()+1,0 )
         oPrint:Textout(REPLICATE("-",40) , .F.)

         oPrint:SetPrc(oPrint:Prow()+1,0 )
         oPrint:Textout("     ", .F.)

         oPrint:SetPrc(oPrint:Prow()+1,0 )
         oPrint:Textout ("  CANT     PRECIO U.      TOTAL" , .F. )

         oPrint:SetPrc(oPrint:Prow()+1,0 )
         oPrint:Textout (" CLAVE      DESCRIPCION" , .F. )

         oPrint:SetPrc(oPrint:Prow()+1,0 )
         oPrint:Textout(REPLICATE("-",40),.F.)
      ENDIF
   ENDIF
Return
Saludos!

IMPRESSÃO DE RELATÓRIOS

Enviado: 04 Dez 2018 21:48
por Jairo Maia
Olá coiote64,

Tanto a solução do Rubens como a solução do Paredes, com certeza serão soluções que você adotará em breve. Intermediário a elas, tem o Win_PrintFileRaw() que pode por enquanto permitir você deixar de usar o NODOSIMP e imprimir seu arquivo texto em qualquer impressora compatível com comandos ESC/POS (RAW).

Claro que como essa função somente é compatível com o modo RAW, em impressoras gráficas não irá imprimir, não sei se o NODOSIMP imprime em impressoras gráficas (não compatível com o modo RAW - ESC/POS).

Amanhã, posto um exemplo de uso com Win_PrintFileRaw() para imprimir um arquivo texto, escolhendo qualquer impressora instalada no Windows.

IMPRESSÃO DE RELATÓRIOS

Enviado: 05 Dez 2018 11:50
por Jairo Maia
Exemplo para imprimir um arquivo texto com Win_PrintFileRaw():

Código: Selecionar todos

/*
  Compilar usando: Hbmk2 Exemplo.Prg hbwin.hbc
  
  Nota: A função Win_PrintFileRaw() não imprime em impressoras gráficas,
        por isso não imprime em impressoras virtuais.
*/

Function Main()
 Local x, cTexto, nCrLf:=Hb_EOL(), cPrinter
 Local nLenLine:=60        // tamanho da linha
 Local cFile:="Teste.Txt"  // nome do arquivo
 
 cTexto := Replicate( "=", nLenLine ) + nCrLf

 For x=1 To 20
  cTexto += PadR( "Linha", ( nLenLine - 2 ), "." ) + StrZero( x, 2 ) + nCrLf
 Next
 
 cTexto += Replicate( "=", nLenLine ) + nCrLf
 
 Hb_MemoWrit( cFile, cTexto )       // cria um arquivo exemplo...
 
 //cPrinter := GetDefaultPrinter()  // pega impressora padrão, ou
 
 cPrinter := MyPrinters()           // seleciona impressora do Windows
 
 Clear Screen
 
 If !Empty( cPrinter )
 
  Win_PrintFileRaw( cPrinter, cFile, "Teste com Win_PrintFileRaw" )  // imprime o arquivo
  
 EndIf
 
Return Nil

Func MyPrinters()
 Local x, nPrn, oPrn, nMaxLen := 0, aPNames := {}
 Local aPrn := Win_PrinterList( .t., .f. )

 If Empty( aPrn )
  Hb_Alert( "Nenhuma impressora Instalada" )
  Return Nil
 Endif

 For x=1 To Len( aPrn )
  AaDd( aPNames , aPrn[x,1] )
  nMaxLen := If( Len( aPrn[x,1] ) > nMaxLen, Len( aPrn[x,1] ), nMaxLen )
 Next

 Clear Screen
 nPrn := AChoice( 5, 10, Len( aPrn )+5, nMaxLen+1, aPNames, .T., Nil , aPNames )
 If nPrn = 0
  Return Nil
 Endi
 Clear Screen

 cPrinter := AllTrim( aPNames[nPrn] )

Return cPrinter