viernes, 10 de octubre de 2008

Impresión Draft

Holas, por cosas del destino aun estoy jugando con VBasic 6 y otra vez a lidear con la dichosa impresión en Draft para una impresora de matriz. Y lo peor es que con windows Xp y los nuevos modelos de Epson como la FX890 el tamaño personlizado de papel NO EXISTE.. asi que a imprimir en RAW MODE nomas usando la libreria winspool.drv. Alguien sabe si esto ya ha sido solucionado con VB2005 o VB2008??
En fin, ahi dejo el codigo necesario para usar esta libreria. :

' Esta parte pueden ponerla en un modulo Draft.bas o lo q quieran
Option Explicit

Public Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type

Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Public Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Public Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Public Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Public Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Public Declare Function EndPage Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long

Global lhPrinter As Long, lreturn As Long, lpcWritten As Long, lDoc As Long, sWrittenData As String, MyDocInfo As DOCINFO

Public Sub Imprimir(Texto As String, Optional Ancho As Integer = 80, Optional Salto As Boolean = True)
If Len(Texto) > Ancho Then
Texto = Left(Texto, Ancho)
End If
If Salto Then Texto = Texto + vbCrLf
lreturn = WritePrinter(lhPrinter, ByVal Texto, Len(Texto), lpcWritten)
End Sub

Public Sub Iniciar_Impresion(DocName As String)
lreturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
MyDocInfo.pDocName = DocName
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
'comprimido
Rem lreturn = WritePrinter(lhPrinter, ByVal Chr$(15) + vbCrLf, Len(Chr$(15) + vbCrLf), lpcWritten)
End Sub

Public Sub Finalizar_Impresion()
lreturn = EndPagePrinter(lhPrinter)
lreturn = EndDocPrinter(lhPrinter)
lreturn = ClosePrinter(lhPrinter)
End Sub


'Y aqui el ejemplo de su uso en un form sencillo con un boton por default
Private Sub Command1_Click()
Dim Linea As String

Iniciar_Impresion("TEST")
Imprimir "HOLA MUNDO"
Imprimir Chr$(15) + vbCrLf ' modo condensado
Imprimir "HELLO WORLD"
Finalizar_Impresion

End Sub

No hay comentarios:

Publicar un comentario