Visual basic

Buenas, hace poco pregunte a un experto como haria para imprimir en visual basic,especificamente estoy desarrollando un programa que imprime en rollos de papel una parte del mismo y quisiera saber como hago para que no provoque un salto de página después que termina de imprimir los datos,me respondieron que configurara la impresora, pero pregunto si existe alguna forma que lo haga a través de código o alguna configuración del windows, en si , lo que quisiera saber es como hago para que la impresión termine después del último dato impreso,sin saltos de página, así como en clipper

1 respuesta

Respuesta
1
Para poder imprimir como vos queres solo existe una opcion y es API,
te paso el codigo:
Agrega un modulo y pone las siguientes declaraciones:
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrn As Long, pDefault As Any) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hprn As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByValhprn As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hprn As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hprn As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hprn As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hprn As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Type DOC_INFO_1
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Public Sub Fin_Spool(ByVal hprn As Long)
'Cerrar impresora
Call EndPagePrinter(hprn)
Call EndDocPrinter(hprn)
Call ClosePrinter(hprn)
End Sub
Public Sub Iniciar_Spool(PrnName As String, hprn As Long)
Dim di As DOC_INFO_1
di.pDocName = "Cadena"
di.pOutputFile = vbNullString
di.pDatatype = "RAW"
Call OpenPrinter(PrnName, hprn, ByVal 0&)
Call StartDocPrinter(hprn, 1, di)
Call StartPagePrinter(hprn)
End Sub
'Continuamos en el modulo:
Public Sub imprimir_Spool(ByVal strCadena As String, ByVal hprn As Long, salto As Integer)
'Imprimir cadena
Dim Buffer() As Byte
Dim Written As Long
Dim i As Long, j As Long
Const BufSize As Long = &H50 '80 CARACTERES
Dim BytesStr As Long
Dim acopiar$
Dim csalto$
Dim cretorno$
Dim veces As Integer
Dim asciicadena As String
asciicadena = strCadena
cretorno = Chr(10) 'Salto linea
csalto = Chr(13) 'Retorno carro
veces = 1
If salto Then veces = 3
Do While veces > 0
If salto Then
If veces = 3 Then 'Cadena
acopiar = asciicadena
Else
If veces = 2 Then 'Salto
acopiar = csalto
Else 'Retorno
acopiar = cretorno
End If
End If
Else 'No salto
acopiar = asciicadena
End If
BytesStr = ((Len(acopiar)) * 2) - 1
ReDim Buffer(1 To BufSize) As Byte
For i = 1 To UBound(Buffer)
Buffer(i) = &H20 'Rellenar a blancos el buffer
Next i
Buffer() = acopiar$ 'Llenar el buffer
Call WritePrinter(hprn, Buffer(0), BytesStr, Written) 'Imprimir
veces = veces - 1
Loop
End Sub
ahora para imprimir un linea de texto tenes que hacer lo siguiente:
'en linea pones el texto a imprimir
Linea = Text2.Text
Dim himp As Long
Call Iniciar_Spool(Printer.DeviceName, himp)
Call imprimir_Spool(Linea, himp, True)
Call Fin_Spool(himp)
Esto lo tengo funcionando bien, si llegaras a tener algun problema, dime el codigo de error y en la linea que corresponda.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas