Transforming a ZPL string into a JPG image and PDF
After some research there seems to be 2 ways of doing this.
Restful call using labreary api:
byte[] zpl = Encoding.UTF8.GetBytes("^xa^cfa,50^fo100,100^fdHello World^fs^xz");
// adjust print density (8dpmm), label width (4 inches), label height (6 inches), and label index (0) as necessary
var request = (HttpWebRequest) WebRequest.Create("http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/");
request.Method = "POST";
request.Accept = "application/pdf"; // omit this line to get PNG images back
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = zpl.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(zpl, 0, zpl.Length);
requestStream.Close();
try {
var response = (HttpWebResponse) request.GetResponse();
var responseStream = response.GetResponseStream();
var fileStream = File.Create("label.pdf"); // change file name for PNG images
responseStream.CopyTo(fileStream);
responseStream.Close();
fileStream.Close();
} catch (WebException e) {
Console.WriteLine("Error: {0}", e.Status);
}
If you cannot rely on a web service and need to have the ability of doing the calls with out sending external requests.
Can I use the Labelary engine locally, without relying on the public web service?
We do offer an offline version of the Labelary engine licensed for local use. Please contact us for licensing information. http://labelary.com/faq.html
This allows us to print out PDFs and PNGs for customers that do not have a zebra printer.
You can try this project BinaryKits.Zpl. It is still an early implementation of a zpl viewer that converts zpl code into an image.
IPrinterStorage printerStorage = new PrinterStorage();
var analyzer = new ZplAnalyzer(printerStorage);
var elements = analyzer.Analyze("^XA^FO100,100^BY3^B3N,N,100,Y,N^FD123ABC^FS^XZ");
var drawer = new ZplElementDrawer(printerStorage);
var imageData = drawer.Draw(elements);