Reputation: 826
What is the best option to send text to the default printer?
The printer is a Zebra, and the text is a string of ZPL.
Many examples out there are with font size, graphics, points (x,y). Very confusing.
But I need to send the string and the printer does its work.
Upvotes: 0
Views: 7726
Reputation: 366
Is your Zebra printer on a network?
If so, this will work-
// Printer IP Address and communication port
string ipAddress = "10.3.14.42";
int port = 9100;
// ZPL Command(s)
string ZPLString =
"^XA" +
"^FO50,50" +
"^A0N50,50" +
"^FDHello, World!^FS" +
"^XZ";
try
{
// Open connection
using (System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient())
{
client.Connect(ipAddress, port);
// Write ZPL String to connection
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream()))
{
writer.Write(ZPLString);
writer.Flush();
}
}
}
catch (Exception ex)
{
// Catch Exception
}
I've used this library successfully as well for USB.
Upvotes: 2
Reputation: 22251
You can open the port directly using a p/invoke to OpenFile
if you are connected using LPT or COM ports, but otherwise you will need to use the print ticket APIs to create a RAW
formatted job. See http://support.microsoft.com/?kbid=322091 for a helper class which calls the appropriate platform functions to allows RAW print jobs from C#.
Upvotes: 2