Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Imprimir en modo texto

Estas en el tema de Imprimir en modo texto en el foro de Visual Basic clásico en Foros del Web. Hola: necesito imprimir un comprobante, en papel continuo, y necesito que la impresion se haga en MODO TEXTO, cual es la sentencia que hace esto?? ...
  #1 (permalink)  
Antiguo 01/03/2006, 22:24
 
Fecha de Ingreso: abril-2004
Ubicación: Añatuya
Mensajes: 95
Antigüedad: 20 años
Puntos: 0
Imprimir en modo texto

Hola:

necesito imprimir un comprobante, en papel continuo, y necesito que la impresion se haga en MODO TEXTO, cual es la sentencia que hace esto??
les comento que utilizo el objeto PRINTER

desde ya muchas gracias y espero su pronta colaboracion
__________________
Un angel le dice a Dios - Señor han descifrado el genoma humano - a lo que Dios contesta - Condenados hackers, voy a tener que cambiar la contraseña
  #2 (permalink)  
Antiguo 01/03/2006, 23:18
Avatar de jc_moty  
Fecha de Ingreso: septiembre-2005
Ubicación: Usulután, El Salvador
Mensajes: 477
Antigüedad: 18 años, 7 meses
Puntos: 1
Cita:
necesito que la impresion se haga en MODO TEXTO, cual es la sentencia que hace esto??
A que te referis con "MODO TEXTO", a un texbox o a que?.
Si es un Texbox, facil:
Código:
   Printer.Print Text1.Text
Saludos
  #3 (permalink)  
Antiguo 02/03/2006, 18:36
 
Fecha de Ingreso: abril-2004
Ubicación: Añatuya
Mensajes: 95
Antigüedad: 20 años
Puntos: 0
No, no es un textbox, son los datos para imprimir comproantes, facturas, remitos, notas de credito, etc en un formulario
ejemplo:

Printer.CurrentX = 800
Printer.CurrentY = 200
Printer.Print "Factura Nº: " & Numero
ETC, ETC, ETC, ETC, ETC
ETC, ETC, ETC, ETC, ETC

pero necesito que sea en modo texto, para que imprima MAS RAPIDO como en modo texto o de ultima hacer que la impresora imprima en DRAFT.

gracias
__________________
Un angel le dice a Dios - Señor han descifrado el genoma humano - a lo que Dios contesta - Condenados hackers, voy a tener que cambiar la contraseña
  #4 (permalink)  
Antiguo 04/03/2006, 12:39
 
Fecha de Ingreso: abril-2004
Ubicación: Añatuya
Mensajes: 95
Antigüedad: 20 años
Puntos: 0
o enviar secuencias de escape a la impresora con el objeto PRINTER, como sería?

gracias....
__________________
Un angel le dice a Dios - Señor han descifrado el genoma humano - a lo que Dios contesta - Condenados hackers, voy a tener que cambiar la contraseña
  #5 (permalink)  
Antiguo 05/03/2006, 12:14
 
Fecha de Ingreso: abril-2004
Ubicación: Añatuya
Mensajes: 95
Antigüedad: 20 años
Puntos: 0
no puedo creer que nadie sepa como hacer lo que necesito o peor seria que lo supieran y no quisieran ayudarme....
__________________
Un angel le dice a Dios - Señor han descifrado el genoma humano - a lo que Dios contesta - Condenados hackers, voy a tener que cambiar la contraseña
  #6 (permalink)  
Antiguo 05/03/2006, 12:59
Avatar de GeoAvila
Colaborador
 
Fecha de Ingreso: diciembre-2003
Ubicación: Antigua Guatemala
Mensajes: 4.032
Antigüedad: 20 años, 4 meses
Puntos: 53
mira hay un ejemplo, lastimosamente no lo metí a las faq's, busca "printer.print" en las busqueda y te a aparecer un ejemplo donde mandas a imprirmir directamente al LPT1

nos vemos..
__________________
* Antes de preguntar lee las FAQ, y por favor no hagas preguntas en las FAQ
Sitio http://www.geoavila.com twitter: @GeoAvila
  #7 (permalink)  
Antiguo 05/03/2006, 13:03
Avatar de GeoAvila
Colaborador
 
Fecha de Ingreso: diciembre-2003
Ubicación: Antigua Guatemala
Mensajes: 4.032
Antigüedad: 20 años, 4 meses
Puntos: 53
estas de suerte.. encontre algo...

http://www.forosdelweb.com/showthrea...=printer.print

nos vemos..
__________________
* Antes de preguntar lee las FAQ, y por favor no hagas preguntas en las FAQ
Sitio http://www.geoavila.com twitter: @GeoAvila
  #8 (permalink)  
Antiguo 06/03/2006, 21:37
 
Fecha de Ingreso: abril-2004
Ubicación: Añatuya
Mensajes: 95
Antigüedad: 20 años
Puntos: 0
bien, ahora como logro ubicar la impresion con este tipo de sentencias en determinado lugar de la hoja???
algo parecido a PRINTER.CURRENTX y PRINTER.CURRENTY
__________________
Un angel le dice a Dios - Señor han descifrado el genoma humano - a lo que Dios contesta - Condenados hackers, voy a tener que cambiar la contraseña
  #9 (permalink)  
Antiguo 08/03/2006, 14:54
Avatar de tampiko  
Fecha de Ingreso: marzo-2006
Ubicación: Mexico, en Villa hace calor, prefiero tampiko
Mensajes: 17
Antigüedad: 18 años, 2 meses
Puntos: 0
Mensaje Cuidado

hola, ten cuidado con la impresion en impresoras de matriz de punto, porke debebas imprimir linea por linea a como van apareciendo, yo tengo ese problema y debes de imprimir en modo texto, el objeto printer y todos sus ventajas sirven de nada, porke son graficos afin de cuenta y lo ke se rekeire es modo texto, te recomiendo "abrir" un archivo llamado LTP1 y ahi escribirle, a la impresora... solo cometneo, estoy trabajando en ello....
  #10 (permalink)  
Antiguo 08/03/2006, 17:01
 
Fecha de Ingreso: abril-2005
Mensajes: 3.083
Antigüedad: 19 años, 1 mes
Puntos: 17
Cita:
Iniciado por tampiko
hola, ten cuidado con la impresion en impresoras de matriz de punto, porke debebas imprimir linea por linea a como van apareciendo, yo tengo ese problema y debes de imprimir en modo texto, el objeto printer y todos sus ventajas sirven de nada, porke son graficos afin de cuenta y lo ke se rekeire es modo texto, te recomiendo "abrir" un archivo llamado LTP1 y ahi escribirle, a la impresora... solo cometneo, estoy trabajando en ello....
En *nix haces:

Código:
echo "hola que tal" > /dev/lpt1
y la impresora empieza con ello... Así que en Windows, quizás pueda funcionar lo de abrir "el LPT1".
  #11 (permalink)  
Antiguo 09/03/2006, 10:54
 
Fecha de Ingreso: marzo-2006
Mensajes: 7
Antigüedad: 18 años, 1 mes
Puntos: 0
Si lo que deseas es enviar comandos directos a la impresora sin utilizar el driver de windows, se puede realizar de la siguiente manera:

1.) Creando un archivo plano, con los comando necesarios para la impresora.
2.) Enviar los comandos directamente a la impresora los datos que se necesitan.

El el proximo correo te envio el objeto que necesitas y el codigo para ejecutarlo.
  #12 (permalink)  
Antiguo 09/03/2006, 11:02
 
Fecha de Ingreso: marzo-2006
Mensajes: 7
Antigüedad: 18 años, 1 mes
Puntos: 0
CODIGO OBJETO PARTE 1-
Esta es la primera parte del objeto


' A very simple printer object used to send data directly
' to the printer.
'
' Date Notes
' 1-12-97Written by [email protected]
Private Const JOB_POSITION_UNSPECIFIED = 0
Private Const MAX_PRIORITY = 99
Private Const MIN_PRIORITY = 1
Private Const DEF_PRIORITY = 1
Private Const JOB_CONTROL_PAUSE = 1
Private Const JOB_CONTROL_RESUME = 2
Private Const JOB_CONTROL_CANCEL = 3
Private Const JOB_CONTROL_RESTART = 4
Private Const JOB_CONTROL_DELETE = 5
'Crear impresora
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Enum PrinterErrors
vbPE_CantOpenPrinter = 2000 ' Can't Open the printer device.
vbPE_CantStartJob ' Can't Start the print job.
vbPE_CantStartPage' Can't start printing a page.
vbPE_UnSentBytes' Some bytes were not successfully sent to the printer.
vbPE_KillDocFailed' Could not cancel the print job.
vbPE_CantChangeName ' Can't change document name.
vbPE_FailedWrite' Failed write to printer.
vbPE_ReadFileError' Could not read from file.
vbPE_CantEndPage' Call to end page failed.
vbPE_CantEndDoc ' Call to close doc failed.
vbPE_CantChangeDevice ' Can't change device while printing.
vbPE_CantCreateDC ' Can't create a device context.
End Enum
Private lPrinter As Long ' Printer handle
Private lBytesWritten As Long' Number of bytes written
Private lBytesSent As Long ' Number of bytes that should have been written.
Private lJob As Long ' Print job handle
Private sDocName As String ' Name of the document
Private sDeviceName As String' Device name.
Private bJobStarted As Boolean ' Have we started a print job.
Private ErrorImpesion As Boolean
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_INFO_2) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As Any) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function SetJob Lib "winspool.drv" Alias "SetJobA" (ByVal hPrinter As Long, ByVal JobId As Long, ByVal Level As Long, pJob As Any, ByVal Command As Long) As Long
Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" (ByVal hPrinter As Long, ByVal JobId As Long, ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As PRINTER_INFO_2) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Long, ByVal lpString2 As String) As Long
'Creado por marco
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type DOC_INFO_1
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type JOB_INFO_1
JobId As Long
pPrinterName As String
pMachineName As String
pUserName As String
pDocument As String
pDatatype As String
pStatus As String
Status As Long
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type
Private Type PRINTER_INFO_2
pServerName As Long 'String
pPrinterName As Long 'String
pShareName As Long 'String
pPortName As String
pDriverName As Long 'String
pComment As Long 'String
pLocation As Long 'String
pDevMode As Long ' DEVMODE
pSepFile As Long 'String
pPrintProcessor As Long 'String
pDatatype As Long 'String
pParameters As Long 'String
pSecurityDescriptor As Long 'SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type

Public Sub NewPage()
If Not bJobStarted Then
NewDoc
Else
'end last page
If EndPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantEndPage, "RAWPrinter", "Can't end page."
Exit Sub
End If

If StartPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantStartPage, "RAWPrinter", "Can't start page."
Exit Sub
End If
End If
End Sub

Sub NewDoc(Optional DocName As String = "", Optional FileName As String = vbNullString)
Dim di As DOC_INFO_1
Dim InfImprsora As PRINTER_INFO_2
Dim Errores
ErrorImpesion = False
Reintentar1:
If bJobStarted Then
EndDoc
End If
If OpenPrinter(sDeviceName, lPrinter, InfImprsora) <= 0 Then
'Err.Raise vbPE_CantOpenPrinter, "RAWPrinter", "Can't Open Printer Device"
'Exit Sub
Call ClosePrinter(lPrinter)
With FormOtraImpresora
.Mensaje ("Impresora no disponible seleccione otra impresora")
.Show 1
sDeviceName = .Impresora
End With
If Len(DeviceName) = 0 Then
ErrorImpesion = True
Exit Sub
End If
GoTo Reintentar1
End If
If DocName <> "" Then
sDocName = DocName
End If

di.pDocName = sDocName & vbNullChar
If FileName = vbNullString Then
di.pOutputFile = FileName
Else
di.pOutputFile = FileName & vbNullChar
End If
di.pDatatype = "RAW" & vbNullChar


lJob = StartDocPrinter(lPrinter, 1, di)

If lJob <= 0 Then
Call ClosePrinter(lPrinter)
With FormOtraImpresora
.Mensaje ("La impresora[" & sDeviceName & "] No esta Disponible, Verificar Conectividad o Seleccione otra impresora")
.Show 1
sDeviceName = .Impresora
End With
If Len(DeviceName) = 0 Then
ErrorImpesion = True
Exit Sub
End If
GoTo Reintentar1
End If
  #13 (permalink)  
Antiguo 09/03/2006, 11:02
 
Fecha de Ingreso: marzo-2006
Mensajes: 7
Antigüedad: 18 años, 1 mes
Puntos: 0
Segunda parte del objeto
If StartPagePrinter(lPrinter) <= 0 Then
With FormOtraImpresora
.Mensaje ("La impresora[" & sDeviceName & "] No esta disponible o conectada al red Seleccine otra impresora")
.Show 1
sDeviceName = .Impresora
End With
If Len(DeviceName) = 0 Then
ErrorImpesion = True
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
ErrorImpesion = True
Exit Sub
End If
GoTo Reintentar1
End If

lBytesWritten = 0
lBytesSent = 0
bJobStarted = True
End Sub

Public Sub KillDoc()
Dim b As Long
If G_LogPRG = 1 Then GenerarLogPRG ("39:0003;")
'Mod Abril 2004
Dim Errores
ErrorImpesion = False

If bJobStarted Then
b = SetJob(lPrinter, lJob, 0, ByVal 0&, JOB_CONTROL_CANCEL)
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Else
b = 0
End If

If b <= 0 Then
Errores = MsgBox("Imposible Cancelar el trabajo de impresion", vbInformation)
'Err.Raise vbPE_KillDocFailed, "RAWPrinter", "Could not cancle the print job."
End If
End Sub

Public Sub EndDoc()
If Not bJobStarted Then
Exit Sub
End If
Dim Errores

If EndPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Errores = MsgBox("No se puede finalizar la pagina", vbInformation)
ErrorImpesion = True
Exit Sub
'Err.Raise vbPE_CantEndPage, "RAWPrinter", "Can't end page."
'Exit Sub
End If

If EndDocPrinter(lPrinter) <= 0 Then
Call ClosePrinter(lPrinter)
bJobStarted = False
Errores = MsgBox("No se puede finalizar el trabajo de Impresion", vbInformation)
ErrorImpesion = True
Exit Sub
End If

Call ClosePrinter(lPrinter)
bJobStarted = False

If lBytesWritten <> lBytesSent Then
Errores = MsgBox("Predida de informacion, Algunos datos no se enviaron a la impresora", vbInformation)
ErrorImpesion = True
'Err.Raise vbPE_UnSentBytes, "RAWPrinter", "Some data was not sent to the printer."
End If
End Sub

Public Property Let DeviceName(Name As String)
If bJobStarted Then
Err.Raise vbPE_CantChangeDevice, "RAWPrinter", "Can't change device while printing."
Else
sDeviceName = Name
End If
End Property

Public Property Get DeviceName() As String
DeviceName = sDeviceName
End Property

Public Property Get DocumentName() As String
DocumentName = sDocName
End Property

Public Sub PrintText(TXT As String)
Dim I As Long
If Not bJobStarted Then
NewDoc
End If

lBytesSent = lBytesSent + Len(TXT)

If WritePrinter(lPrinter, ByVal TXT, Len(TXT), I) = 0 Then
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False

Err.Raise vbPE_FailedWrite, "RAWPrinter", "Failed write to printer."
Exit Sub
End If

lBytesWritten = lBytesWritten + I
End Sub

Public Sub PrintFile(fname As String)
Dim fh As Long
Dim Buffer As String
Dim fl As Long
Dim r As Long
Dim I As Long
Dim bs As Long
If G_LogPRG = 1 Then GenerarLogPRG ("39:0010;")
If Not bJobStarted Then
NewDoc
End If

fh = FreeFile(0)
bs = 8192
Buffer = String(bs, 0)

Open fname For Binary Access Read As fh
fl = LOF(fh)
r = 0

If fl = 0 Then
Close fh
Exit Sub
End If

Do
If fl - r < bs Then
bs = fl - r
Buffer = String(bs, 0)
End If

Get fh, , Buffer

lBytesSent = lBytesSent + bs
r = r + bs

If WritePrinter(lPrinter, ByVal Buffer, bs, I) = 0 Then
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
On Error GoTo 0
Err.Raise vbPE_FailedWrite, "RAWPrinter", "Failed write to printer."
Exit Sub
End If

lBytesWritten = lBytesWritten + I
Loop While r <> fl

Close fh
Exit Sub

PrintFileError:
On Error Resume Next

Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Close fh

On Error GoTo 0
Err.Raise vbPE_ReadFileError, "RAWPrinter", "Could not read from file."
End Sub

Private Sub Class_Initialize()
sDocName = "Simple"
bJobStarted = False
End Sub
Public Sub SelectImpresora(Impresora As String)
If G_LogPRG = 1 Then GenerarLogPRG ("39:0012;")
sDeviceName = Impresora
End Sub
Private Sub Class_Terminate()
If G_LogPRG = 1 Then GenerarLogPRG ("39:0013;")
If bJobStarted Then
EndDoc
End If
End Sub

Public Property Get hPrinter() As Long
If G_LogPRG = 1 Then GenerarLogPRG ("39:0014;")
hPrinter = lPrinter
End Property

Public Property Get hJob() As Long
If G_LogPRG = 1 Then GenerarLogPRG ("39:0015;")
hJob = lJob
End Property

Public Property Get Priority() As Long
Dim di As String ' stores JOB_INFO_1
Dim I As Long
If G_LogPRG = 1 Then GenerarLogPRG ("39:0016;")
Call GetJob(lPrinter, lJob, 1, ByVal di, 0, I)
di = String(I, 0)
Call CopyMemory(I, ByVal (Mid$(di, 33, 4)), 4)

Priority = I
End Property
' Bug: Doesn't work?
Public Property Let Priority(ByVal I As Long)
Dim di As JOB_INFO_1
If G_LogPRG = 1 Then GenerarLogPRG ("39:0017;")
'JobId, pPrinterName, pMachineName, pDrivername,
'Size, Submitted, and Time are ignored
If I < MIN_PRIORITY Then
I = DEF_PRIORITY
ElseIf I > MAX_PRIORITY Then
I = MAX_PRIORITY
End If

di.Priority = I
di.Position = JOB_POSITION_UNSPECIFIED
di.pUserName = vbNullString
di.pDocument = vbNullString
di.pDatatype = vbNullString
di.pStatus = vbNullString
di.Status = 0
di.TotalPages = 0
di.PagesPrinted = 0

Call SetJob(lPrinter, lJob, 1, di, 0)
End Property

Public Function Errores() As Boolean
Errores = ErrorImpesion
End Function

Public Function EstadoImpresora() As Boolean
EstadoImpresora = bJobStarted
End Function

Private Function AddString(strString As String, ByRef bBuffer() As Byte) As Long

'************************************************* ********************
' AddString copies a string into a Byte array and returns a long
' pointer to that string
'************************************************* ********************

Dim lngEnd As Long
lngEnd = UBound(bBuffer) + 1
Do
lngEnd = lngEnd - 1
Loop While (bBuffer(lngEnd) = 0 And lngEnd > 0)
lngEnd = lngEnd + 2

lstrcpy VarPtr(bBuffer(0)) + lngEnd, strString

AddString = VarPtr(bBuffer(0)) + lngEnd
End Function
  #14 (permalink)  
Antiguo 09/03/2006, 11:04
 
Fecha de Ingreso: marzo-2006
Mensajes: 7
Antigüedad: 18 años, 1 mes
Puntos: 0
codigo Uso:
*********
dim ImpSalida as RawPrinter
Set ImpSalida = New RAWPrinter

' *** Inicializacion obj
ImpSalida.SelectImpresora ("nombre de la impresora de windows")
ImpSalida.NewDoc ("texto de salida en el manejador de spool de windows")

' *** envio del archivo plano
nomsalida="c:\desarrollo\test.txt"
ImpSalida.PrintFile NomSalida

' **** envio de datos a la impresora
Salida=crh(27) & "F Texto en negrilla"
ImpSalida.PrintText Salida

' ***** Cierre de la impresion
ImpSalida.EndDoc
Set ImpSalida = Nothing
  #15 (permalink)  
Antiguo 10/03/2006, 02:38
Avatar de Jefe_Negro  
Fecha de Ingreso: diciembre-2005
Mensajes: 50
Antigüedad: 18 años, 4 meses
Puntos: 0
En Configuracion, Impresoras y Faxes, añade manualmente una nueva impresora seleccionando, Genericas, Generic Text Only. Selecconala desde VB y a partir de ahi, cualquier print quel lances a la impresora el driver se encargara de enviarlo en modo texto.
__________________
Un Saludo
Jefe Negro.


PDF desde ASP ó VB6 Gratis: http://www.oPDF.tk
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:29.