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#.
c# send plain text to default printer (Zebra printer)
-
30-06-2022 - |
Question
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.
Solution
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow