É soh gerar um simples TXT com nome de TEXTO.TXT e no final fazer achamada de :
Código: Selecionar todos
Func Main
arq="c:\imp.txt"
if !file(arq)
arqh=fcreate(arq,0)
if !arqh>0
quit
endif
txt="IMP ABERTO"
txt_t=fwrite(arqh,txt)
if !txt_t=len(txt)
quit
endif
fclose(arqh)
endif
janela2=fopen(arq,18)
if !janela2>0
quit
endi
rele arq, arqh, janela2, txt, txt_t
IMPRES()
Return Nil
FUNC IMPRES
LOCAL aPrn := PRINTERPORTTONAME( "PDF", .T. ) // usa a impressora PDF criator para imprimir via PDF
IF EMPTY( PRINTERPORTTONAME( "PDF", .T. ) )
aPrn := GETDEFAULTPRINTER() // caso a PDFCREATOR não exista ele vai pegar a impressora padrão
ENDIF
IF !FILE("TEXTO.TXT")
RETURN
ELSE
inkey(5)
cFILE := "C:\LEO"+ ALLTRIM( STR( RANDOM(9999) ))+".TXT"
COPY FILE TEXTO.TXT TO (cFILE)
DELETE FILE TEXTO.TXT
ENDIF
If Empty(aPrn)
alert("Não tem Impressora Instalada")
else
Imprime(cFILE,aPrn)
EndIf
DELETE FILE C:\TEXTO.DBF
RETURN
FUNC Imprime( cArq,cPrinter )
local cTexto, nLinhas, nA, cLinha
local oPrinter := win32prn():New(cPrinter)
oPrinter:Landscape := .F.
oPrinter:FormType := 9
oprinter:SetPrintQuality(-1)
oPrinter:Copies := 1
IF FILE("logo.bmp") // se tiver o arquivo logo.bmp dentro da mesma pasta ele vai imprimir o logo primeiro
aTamlog := 9
else
aTamlog := 0
endif
DELETE FILE C:\TEXTO.DBF
vARQ:={}
aadd( vARQ, {"LINHA","C",200,0} )
DBcreate("C:\TEXTO.DBF", vARQ)
SELE 40
USE C:\TEXTO ALIAS TELA EXCL
SELE TELA
append from (cArq) sdf
IF !oPrinter:Create()
return NIL
ELSE
IF ! oPrinter:StartDoc("SAGI")
return NIL
endif
PrintBitMap( oPrinter )
FOR TT=1 TO aTamlog
oPrinter:newline()
NEXT
oPrinter:SetFont("Courier New",11,{3,-50})
oPrinter:Bold(0)
SELE TELA
dbgotop()
Do while !eof()
cLinha := Tela->Linha
oPrinter:newline()
oPrinter:SetFont("Courier New",11,{3,-50})
oPrinter:TextOut(cLinha)
oPrinter:Bold(0)
dbskip()
if !eof()
if (oPrinter:MaxRow() - 2) <= oPrinter:Prow()
oPrinter:NewPage() // novo pagina
PrintBitMap( oPrinter ) // imprimindo o logotipo de novo
FOR TT=1 TO aTamlog
oPrinter:newline()
NEXT
endif
endif
enddo
oPrinter:EndDoc()
oPrinter:Destroy()
ENDIF
SELE TELA
USE
RETURN NIL
FUNC PrintBitMap( oPrn ) //função para imprimir imagem do logotipo
LOCAL oBMP
oBMP:= Win32BMP():new()
oBmp:loadFile( "logo.bmp" )
oBmp:Draw( oPrn, { 200,200,500,500 } )
oBMP:Destroy()
RETURN
FUNC Random( nLimite ) // função para criar um arquivo temporario
static nGuarda:= 1
local I
local nResult
if ValType( nLimite ) # [N]
nLimite:= 100
endif
I:= Seconds()
while nLimite > I
I:= I * 100 +Seconds()
enddo
nGuarda:= (nGuarda +I) / (nResult:= nGuarda * I % nLimite +1)
nResult:= Int( nResult )
return nResult


