Interfacing to UPS (and FedEx) to ship packages is fairly straightforward. The carriers each have a web api to create the shipment and generate a shipping label. For UPS, the application can generate an XML document with the shipment details and post it an api endpoint. The api returns an XML document with the shipment details, including shipping cost, tracking number, and a shipping label.

The shipping label can be generated in a variety of formats, such as an PNG or GIF file, a PDF, or as an EPL/ZPL file. An EPL/ZPL file is a actually a set of commands to render the label (similar in principle to Postscript) that works with Zebra tag printers.bigda402

Labels can be printed to any type of printer, but dedicated tag printers such as this Zebra are commonly used in higher volume shipping operations.

Since the EPL/ZPL is the actual commands to be sent to the printer, it isn’t printed via a printer driver. It needs to be sent directly to the printer, bypassing the print driver. To print this type of print job, we created a helper application that accepts a raw printer file and a named printer and sends the file directly to the print spooler. The API calls we need are in winspool.drv.

The basic workflow is

  1. Call OpenPrinter with the printer name and get a handle
  2. Start a document with StartDocPrinter
  3. Start a page with StartPagePrinter
  4. Send the data to the printer with WritePrinter
  5. End the page with EndPagePrinter
  6. End the document with EndDocPrinter
  7. Finally, close the printer with ClosePrinter

The program displays no user interface, it simply takes the file and sends it directly to the print spooler.  It’s a console application that’s meant to be called from other applications.

The source is available on GitHub, and is called (oddly enough) PrintRaw.

It’s based on code from a KB article.

One thought on “PrintRaw project on GitHub

Leave a Reply

Your email address will not be published.