The text of this article is not in this database — only its details are. Read it on the old site: Printing directly to the Printer
10 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Printing directly to the Printer
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
Enel AlmontePosted Feb 3, 2011, 10:41 AM
Imports System.Runtime.InteropServices ''' <summary> ''' Shows how to write data directly to the printer using Win32 API's ''' </summary> ''' <remarks>Adapted from Microsoft Support article Q298141 ''' and http://www.vbdotnetheaven.com/UploadFile/jodonnell/PrintingDirectly04202005010211AM/PrintingDirectly.aspx ''' </remarks> ''' Public Class PrintDirect Public Structure DOCINFO Dim pDocName As String Dim pOutputFile As String Dim pDatatype As String End Structure <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function OpenPrinter(ByVal pPrinterName As String, ByRef phPrinter As IntPtr, ByVal pDefault As Integer) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function StartDocPrinter(ByVal hPrinter As IntPtr, ByVal Level As Integer, ByRef pDocInfo As DOCINFO) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function StartPagePrinter(ByVal hPrinter As IntPtr) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function WritePrinter(ByVal hPrinter As IntPtr, ByVal data As String, ByVal buf As Integer, ByRef pcWritten As Integer) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EndPagePrinter(ByVal hPrinter As IntPtr) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr) As Long End Function <DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Long End Function Public Shared Sub Print(ByVal StringToPrint As String, ByVal PrinterName As String) Dim lhPrinter As New System.IntPtr() Dim di As New DOCINFO() Dim pcWritten As Integer = 0 di.pDocName = "Impresion Desde AsVentas" di.pDatatype = "RAW" 'lhPrinter contains the handle for the printer opened 'If lhPrinter is 0 then an error has occured OpenPrinter(PrinterName, lhPrinter, 0) StartDocPrinter(lhPrinter, 1, di) StartPagePrinter(lhPrinter) Try WritePrinter(lhPrinter, StringToPrint, StringToPrint.Length, pcWritten) Catch ex As Exception MsgBox("Error al Imprimir: " & vbCr & ex.Message) Finally EndPagePrinter(lhPrinter) EndDocPrinter(lhPrinter) ClosePrinter(lhPrinter) End Try End Sub End Class
saritha praveenPosted Jan 7, 2011, 5:09 AM
sir where i place this code in form
Yesudasan MosesPosted Sep 9, 2010, 5:24 AM
Hi Thanks this work fine for me.. pls tell me how can i make the text bold underline or italic??
jeno winningPosted Sep 15, 2009, 2:20 AM
Its possible to print image using Winspool drv
Liju MathewPosted Jan 17, 2008, 7:48 AM
I've used this code. But its not printing. It is reaching the printer. But not printing. Other documents are getting printer so no problem with printer
Nelima PatelPosted Jul 13, 2007, 11:11 AM
Is there a way to print jpeg images with this code sample? Thanks
Ali SianatiPosted Apr 25, 2007, 5:19 AM
hi,how can i print images using above codes? thanks
Ali SianatiPosted Apr 25, 2007, 5:13 AM
hi,how can i print images using above codes? thanks
saiju josePosted Apr 5, 2007, 2:39 AM
This topic was realy helpful for me, Thank u so much ........