Good Afternoon Developers! Today I’m continuing my discussion of printing from webpages. For my first post, see here.
Thankfully with http you can print from a mobile device, smartphone, tablet, or PC. No drivers are necessary, so Android devices without drivers can use this to print. No one has to install or run any software besides a browser. All this makes it very flexible to the devices your web app can be run on.
There are several limitations for this mode of printing. One is that you as a developer have to create the label yourself. Zebra printers primarily use a print language called ZPL. Normally the driver handles the conversion from document to print language. Another is some of the browser security settings block communicating to the printer. The third limitation is that there is no bi-directional capability. There is no way to verify if a printer is online or is capable of printing before or after sending a print job. Use this feature only in situations where it is not critical that the print job gets done, or you can easily reprint if the printer was off or out of paper. Another limitation with http printing is that the printer must be networked on the same network as the user. USB and Bluetooth connectivity are not options with this technology.
The easiest way to handle creating a print job is to install the Zebra Driver and set it up for how you want the labels to be printed. Then take a label design tool like Zebra Designer to create a reusable document format. If you are printing in a specific application, say shelf labels, most of the time you want the price always in one area of the label, and the UPC in another area. You can use Zebra Designer to lay this template out. When you want to print, you just send the basic information of the UPC and price for each label. This speeds up time to print and ensures the best quality images. You can also manipulate the ZPL directly as a simple text file. The Programming Guide has examples of how to do this. It also explains how to set up printers for Wi-Fi, as well as document formatting.
- Name badge demo: Shows how to take basic user input and embed it directly in a raw ZPL print string and print it.
- Type your own ZPL Script: Essentially the same as the other basic html page, take what’s in the textbox and send it as raw data to the printer.
- Print Configuration Label: Simple string to print status and setup information about the printer
- Print Labels from your Computer: Does the same thing as demo #4, but gets the templates from the local user’s PC instead of the server.
For the demos that print formats, there are two different types of formats, standard ZPL, and XML. XML printing is useful if data is already formatted in XML, say from a database.
The files that are in this Zip file are:
- ZCloudDemo.css: A standard css to make the webpage look nice and Zebra-ish.
- Cloud_Connect.png, Zebra_Tag_Horizontal.png, and icon.ico: images to make the page look nice and Zebra-ish.
- File_catalog.xml: used by the “Print Zebra Demo labels” functionality to provide a list of zpl files for users to choose from (without a PHP or ASP backend)
- Test.txt, test2.txt, and herbert2.txt: basic ZPL print format files used by the “Print Zebra Demo labels” demo.
To try it yourself, simply extract the zip folder anywhere on your computer and double click the HTTPPost_printing.html file. This will open your favorite internet browser. You will need to input the IP address of your Zebra printer, then you should be ready to print. If you are using Chrome or IE10+, the “Print Zebra Demo labels” demo won’t work unless you are running it from IIS.
Edit: If you are having a problem with print-jobs not going through, check the console log. If you see an error along the lines of "Access-Control-Allow-Origin header not found", please see my post Http POST printing and CORS.
For more information, see the Zebra Knowledge Management site.
To ask questions, see our Launchpad page.
Other Articles on this topic:
ISV Engineer - Zebra Technologies
HttpPost_Demo.zip 72.7 K