La Web del Programador: Comunidad de Programadores
 
    Pregunta:  41656 - IMPRIMIR DESDE VISUAL.NET
Autor:  Miguel Beltrán Soto
Quiero imprimir desde visual.net a una impresora generic only / text , intente usar el printdocument pero me marca error solo en estas impresoras.. Como ´puedo solucionar este problema??

  Respuesta:  Carlos M. Castillo Umanzor
prueba con (la segunda funcion la encontré en la documentación de dot Net, la primera fue una adaptacion para que imprimiera directamente un file):

Dim printFontType As Font
Dim strReader As StreamReader
Dim myCadena As String

Public Sub PrintDoc(ByVal NombreArchivo As String)
Dim cadRuta As String

Try
cadRuta = Application.StartupPath & "\OUTPUT"
strReader = New StreamReader(cadRuta & "\" & NombreArchivo)

Try
printFontType = New Font("Arial", 8)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf pd_PrintPage
pd.Print()
Finally
strReader.Close()
End Try

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFontType.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
line = strReader.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFontType.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFontType, Brushes.Black, leftMargin, _
yPos, New StringFormat)
count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub