Página 1 de 4

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 12:14
por rbonotto
Bom dia pessoal, estou migrando clipper->harbour, e estou com uma duvida bem basica sobre imprimir o conteudo de um arquivo.

No clipper usava o comando run type xxx.xxx >prn, mas no harbour não esta funcionando ( nem dando erro, passa batido )
Qual seria o equivalente em harbour ?

- impressora esta na LPT1
- WinXP e Win7

abraços,

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 12:31
por Imatech

Win_PrintFileRaw( 'LPT1', c_Arquivo_para_Impressao, 'Impressão: PrintFileRaw' )

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 17:21
por rbonotto
Obrigado, funcionou perfeitamente ! :D

Este comando imprimiria em USB ?

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 17:40
por Imatech
Sim: Qualquer impressora instalada no Windows

Pegue o nome da impressora usando: Win_PrintDlgDC

Código: Selecionar todos


  LOCAL xPrn := ''
  Win_PrintDlgDC( @xPrn,,, )

  IF !( EMPTY( xPrn ) )
    Win_PrintFileRaw( xPrn, c_Arquivo_para_Impressao, 'Impressão: PrintFileRaw' )
  ENDIF


Comando de impressão de arquivo.

Enviado: 18 Jul 2012 20:25
por Pablo César
Ronaldo (Imatech) escreveu:
rbonotto escreveu:Este comando imprimiria em USB ?
Sim: Qualquer impressora instalada no Windows
Correção: Existe uma limitação nessa função, ela apenas imprime em impressoras que dão suporte a impressão RAW MODE (Palavras do nosso colega Leonardo). Nem todas as impressoras, oferecem esta forma de impressão.

Veja em propriedades da impressora se possui ou não o padrão RAW:
Imagem

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 21:21
por Imatech
Olá meu amigo Pablo !



Para o tipo de impressão desejado todas as impressoras que o usuario já utilizava serão compativeis...

Alem do acrescimo de toda a Linha de impressoras EPSON/HP ( Linguagem Esc/P e/ou PCL ) que estiverem instaladas no windows...




Abç...

Comando de impressão de arquivo.

Enviado: 18 Jul 2012 21:33
por Pablo César
Com PrintFileRaw não é garantido a impressão em TODAS as impressoras.

Em alguns modelos de impressoras como: Canon, Samsung, Lexmark, Zebra e outras impressoras especializadas que apenas utilizam drives específicos como para impressão de fotografias, não utilizam o padrão RAW. Daí o Win_PrintFileRaw não funcionará, por isso é recomendado avaliar o retorno da função se retornar -1 é porque a impressora não suporta este padrão para o spooler do WIndows.

Comando de impressão de arquivo.

Enviado: 19 Jul 2012 12:08
por rbonotto
Os meus clientes usam quase que 100% impressoras das marcas Bematech, Diebold ou Daruma.

Testei em uma Bematech e funcionou perfeitamente, testarei em outros e posto resultado.

Novamente, obrigado !!

Comando de impressão de arquivo.

Enviado: 19 Jul 2012 23:28
por JoséQuintas
Não tenho como testar, mas se funciona a impressão normal, acredito que possa funcionar algo do tipo:
set console off
set printer on
type arquivo
set printer off
set console on

Comando de impressão de arquivo.

Enviado: 21 Ago 2012 11:48
por helio
Pessoal onde posso encontrar esta Funcao Win_PrintFileRaw().

Comando de impressão de arquivo.

Enviado: 21 Ago 2012 12:05
por Pablo César
Helio você pode procurar pela função hb_PrintFileRaw
Tela41.PNG
Também você pode criar sua própria rotina em C, como por exemplo esta aqui:

Código: Selecionar todos

#pragma BEGINDUMP

#undef UNICODE

#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"

#ifndef __XHARBOUR__
   #define ISCHAR( n )           HB_ISCHAR( n )
#endif

#define MAX_FILE_NAME 1024
#define BIG_BUFFER (1024*32)

HB_FUNC ( ENUMPRINTERS )
{
  UCHAR *Result ;
  DWORD x, Flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ;
  LPSTR Name = NULL ;
  DWORD Level = 5 ;
  PRINTER_INFO_5 *pPrinterEnum, *pFree;
  PRINTER_INFO_4 *pPrinterEnum4, *pFree4;
  DWORD cbBuf  ;
  DWORD BytesNeeded=0 ;
  DWORD NumOfPrinters=0 ;
  OSVERSIONINFO osvi ;  //  altered to check Windows Version
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  GetVersionEx (&osvi);
  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  {
    Level = 4 ;
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree4 = pPrinterEnum4 = (PRINTER_INFO_4 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum4++ )
        {
          strcat(Result,pPrinterEnum4->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree4) ;
    }
    else
      hb_retc("") ;
  }
  else
   {
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree = pPrinterEnum = (PRINTER_INFO_5 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum++ )
        {
          strcat(Result,pPrinterEnum->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree) ;
    }
    else
      hb_retc("") ;
  }
}

HB_FUNC( WINDEFAULTPRINTER )
{
  DWORD x, y ;
  UCHAR lpReturnedString[MAX_FILE_NAME] ;
  x = GetProfileString("windows","device","",lpReturnedString,MAX_FILE_NAME-1);
  y = 0 ;
  while ( y < x && lpReturnedString[y] != ',' )
    y++ ;
  hb_retclen(lpReturnedString,y) ;
}

HB_FUNC( PRINTFILERAW )
{
  UCHAR  printBuffer[BIG_BUFFER], *cPrinterName, *cFileName, *cDocName ;
  HANDLE  hPrinter, hFile ;
  DOC_INFO_1 DocInfo ;
  DWORD nRead, nWritten, rVal = -1 ;
  if (ISCHAR(1) && ISCHAR(2))
  {
    cPrinterName= (UCHAR*)hb_parc(1) ;
    cFileName= (UCHAR*)hb_parc(2) ;
    if ( OpenPrinter(cPrinterName, &hPrinter, NULL) != 0 )
    {
      DocInfo.pDocName = (UCHAR*)hb_parc(3) ;
      DocInfo.pOutputFile = NULL ;
      DocInfo.pDatatype = "RAW" ;
      if ( StartDocPrinter(hPrinter,1,(char *) &DocInfo) != 0 )
      {
        if ( StartPagePrinter(hPrinter) != 0 )
        {
          hFile = CreateFile(cFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)   ;
          if (hFile != INVALID_HANDLE_VALUE )
           {
            while (ReadFile(hFile, printBuffer, BIG_BUFFER, &nRead, NULL) && (nRead > 0))
            {
              if (printBuffer[nRead-1] == 26 )
                nRead-- ; // Skip the EOF() character
              WritePrinter(hPrinter, printBuffer, nRead, &nWritten) ;
            }
            rVal = 1 ;
            CloseHandle(hFile) ;
          }
          else
            rVal= -6 ;
          EndPagePrinter(hPrinter) ;  // 28/11/2001 10:16
        }
        else
          rVal = -4 ;
        EndDocPrinter(hPrinter);
      }
      else
        rVal= -3 ;
      ClosePrinter(hPrinter) ;
    }
    else
      rVal= -2 ;
  }
  hb_retnl(rVal) ;
}

#pragma ENDUMP
E utilizar em Harbour com este exemplo:

Código: Selecionar todos

FUNCTION WinPrintRaw(cPrinter,cFileName,cDocumentName)
//////////////////////////////
  LOCAL nPrn:= -1, cMess:= "WinPrintRaw(): "

  IF !EMPTY(cFilename)
    IF (nPrn := PrintFileRaw(cPrinter,cFileName,cDocumentName)) < 0
      DO CASE
      CASE nPrn = -1
        Alert(cMess+"Incorrect parameters passed to function")
      CASE nPrn = -2
        Alert(cMess+"WINAPI OpenPrinter() call failed")
      CASE nPrn = -3
        Alert(cMess+"WINAPI StartDocPrinter() call failed")
      CASE nPrn = -4
        Alert(cMess+"WINAPI StartPagePrinter() call failed")
      CASE nPrn = -5
        Alert(cMess+"WINAPI malloc() of memory failed")
      CASE nPrn = -6
        Alert(cMess+"WINAPI CreateFile() call failed - File "+cFileName+" no found??")
      ENDCASE
    ENDIF
  ENDIF

RETURN(nPrn)

//////////////////////////////
STATIC FUNCTION PrintMessage(cPrinter)
//////////////////////////////
  SET CONS OFF
  SET ALTE TO (TESTFILE)
  SET ALTE ON
  ? ' PRNTEST.PRG'
  ?
  ? '  Copyright:'
  ? '   Rees Software & Systems Ltd 2003'
  ? '   Nelson, New Zealand'
  ?
  ? ' Contents :'
  ? '    Sample printing to file'
  ? '    This is donated to the public domain and is free software.'
  ?
  ? 'An alternative to "SET PRINTER TO" for printing under Windows'
  ? '-------------------------------------------------------------'
  ?
  ? 'Print to a temporary file (we use WINAPI GetTempFileName()) first. Then use'
  ? 'WinPrintRaw() to send the file to the windows spooler.'
  ?
  ? 'Obviously to make use of this you need to know what type of printer you are'
  ? 'printing to and you must also include the appropriate "Escape codes" in the'
  ? 'file - as we used to do in Clipper. The trick we use to determine what type'
  ? 'of printer is installed is to add special characters to the Windows printer'
  ? 'name.'
  ?
  ? '(E)= Epson compatible DOT matrix e.g. Panasonic KXP3200 Series (E)'
  ? '(6)= PCL 6 compatible'
  ? '(D)= Deskjet'
  ? ''
  ? 'etc....'
  ?
  ? 'Then to determine the correct "Escape codes" do the following in your code:'
  ?
  ? 'BEGIN CASE'
  ? "CASE '(6)'$cPrinter"
  ? "   s_prnReset = CHR(27)+'E'+........"
  ? '   s_underOn  = CHR(27)+"&d1D"'
  ? '   s_UnderOff = CHR(27)+"&d@"'
  ? "   s_compress = CHR(27)+ '(s1b16.66h6T'"
  ? '  file://etc....'
  ? "CASE '(E)'$cPrinter"
  ? '  file://etc......'
  ? 'ENDCASE'
  ?
  ? 'This is the exact same approach we used in Clipper - except that printing'
  ? 'is to the Windows printer not a LPT port. The only caveat is that not all'
  ? 'printers support RAW mode. These are Windows GDI only printers.'
  ?
  ? 'We have been using this approach for the last 4 years with Xbase++ with no'
  ? 'problems.'
  ?
  ? FORMFEED
  SET ALTE OFF
  SET ALTE TO
  SET CONS ON
  WinPrintRaw(cPrinter, TESTFILE, "Test Print Job")
RETURN(.T.)

//////////////////////////////
FUNCTION WinGetPrinters()
//////////////////////////////
  LOCAL aPrn := {}, nStart := 1, cPrinters, nStop, nPos, cPrn
  cPrinters := EnumPrinters()+';'
  nStop := LEN(cPrinters)+1
  DO WHILE nStart < nStop
    nPos := AT(';', cPrinters, nStart)
    IF !EMPTY(cPrn := SUBSTR(cPrinters, nStart, nPos-nStart))
      AADD(aPrn, cPrn)
    ENDIF
    nStart := nPos+1
  ENDDO
RETURN(aPrn)
Código obtido do C:\MiniGUI\SAMPLES\Advanced\PrintRAW\PRINTRAW.PRG

Comando de impressão de arquivo.

Enviado: 21 Ago 2012 12:19
por helio
Pablo,
Utilizo ainda o XHARBOUR 0.977 com SQLRDD e nao consegui achar estar funcao voce podia me ajudar ou nao tem neste XHARBOUR que utilizo.

Comando de impressão de arquivo.

Enviado: 21 Ago 2012 12:23
por Pablo César
xHarbour ? Não é muito a minha praia... e ainda essa versão... mas já experimentou utilizando PrintFileRaw() ?

Comando de impressão de arquivo.

Enviado: 22 Ago 2012 09:30
por helio
Pablo,

Esta funcao WinPrintRaw(cPrinter,cFileName,cDocumentName) os parametros exemplo: cPrinter = 'LPT2', cFileName = ARquivo a ser impresso, cDocumentName = ?

Comando de impressão de arquivo.

Enviado: 22 Ago 2012 11:10
por Imatech
Olá Helio !


Não precisa anexar coisas que já existam no seu compilador ( PrintFileRaw é originario do xharbour, no Harbour a função foi renomeada para Win_PrintFileRaw )


Com xHarbour ira usar a função: PrintFileRaw()


cPrinter := 'LPT2' // porta ou nome da impressora no gerenciador de impressoras do windows
cFileName := ARquivo a ser impresso // nome do arquivo a ser impresso
cDocumentName := 'Meu relatorio usando PrintFileRaw' // Titulo qualquer a ser exibido pelo gerenciador de impressão


PrintFileRaw( 'LPT2', '\temp\teste_impressao.txt', 'Meu relatorio usando PrintFileRaw' )