Home    
Log In    
Share Code    
Join    

Navigation
 Skip Navigation Links.

Forums
Skip Navigation Links.

Search

 

Advertisement
 
VB.NET Source Code > Print RAW data to Network Printers Source Code
Details
Author: ptaylor
Views: 876

Print RAW data to Network Printers
Description
Send prints to a Network printer

Originally designed to send ZPL commands to Zebra S4M using an HP Jet Direct this code will send RAW print jobs to and network printer, Including Dot-Matrix and Thermal Transfer Printers
 
 
Code:
Dim strPrintData as String 'Contains the string to be printed
Dim DataBytes() As Byte 'Contains the String converted into bytes

Dim PrintedStream As NetworkStream 'Stream to transmit the bytes to the Network printer
Dim HostIPAddress As System.Net.IPAddress 'IP Address of the Printer
Dim PrinterPort As New System.Net.Sockets.TcpClient 'TCPClient to comunicate


Try
    If Me.strPrintData IsNot Nothing Then

        'Convert the string into bytes
        DataBytes = System.Text.Encoding.ASCII.GetBytes(Me.strPrintData)

        'If Not connected then connect
        If Not PrinterPort.Client.Connected Then
            'Printer Port 9100 for HP JetDirects
            PrinterPort.Connect(HostIPAddress, 9100)
        End If

        PrintedStream = PrinterPort.GetStream

        'Send the stream to the printer
        If PrintedStream.CanWrite Then
            PrintedStream.Write(DataBytes, 0, DataBytes.Length)
        End If

        'Close the connections
        PrintedStream.Close()
        PrinterPort.Close()
    End If
Catch ex As Exception
    Throw New Exception(ex.Message)
End Try  
Date Added: 06/04/2009 20:31:38





Comments


If you log in you can add a comment of your own!
 
 
Welcome Guest
 
  Log In Name
 
  Password
 
 
Statistics
Your Details: Not Logged In
  Join Date: N/A
  Last Logon: N/A
  Code Snippets: N/A
  Code Comments: N/A
  Forum Posts: N/A
  Forum Subjects: N/A

Site Wide
  Code Snippets: 32
  Code Comments: 2
  Forum Posts: 52
  Forum Subjects: 24
 
Random Code
Add Meta Tags to ASP.NET Pages
How to add Meta Tags to ASP.NET Pages programmatic....

Language: ASP.NET

 
Advertisement


All the Source Code and Tutorials on this site are free for you to use as you require.