-
Notifications
You must be signed in to change notification settings - Fork 6
Documentation
This extension provides two functions:
- Javascript API to integrate into your own web app
- Utility page for quick one off printing
This is the main functionality. Many Zebra printers provide a HTTP POST endpoint to which a ZPL string can be posted and the printer will print it.
In short: Modern browsers enforce Content Security Policies (CSP) which will prevent you from doing this. There are many polices but the most relevant for this case is (1) posting from HTTPS to HTTP and (2) Cross Origin Resource Sharing (CORS).
Zebra's HTTP endpoint has no SSL (HTTPS) option and no CORS headers are set. This extension bypasses those issues.
The Javascript API is simple to use. There are two components which will enable ZPL code printing.
If this extension is installed and successfully injected into your web page you can listen to a message it will send into every window:
window.addEventListener("message", function (event) {
if (!event.data.ZebraPrintingVersion) {
return;
}
console.log(event.data);
});
This will return an object providing you with the following information:
{
ZebraPrintingExtensionId: "ndikjdigobmbieacjcgomahigeiobhbo",
ZebraPrintingVersion: "1.5"
}
Based on that, you can enable a label printing function in your web app. But this is not a requirement but soley a helper for you to build your web app more user friendly.
window.postMessage({
type: "zebra_print_label",
zpl: "^XA^FO20,20^A0N,30,30^FDThis is a TEST^FS^XZ",
url: "http://192.168.38.10/pstprnt"
}, "*");
What we are doing here is sending (window.postMessage()
) a message containing the printer's POST endpoint, your ZPL code and a type
information to the window
. This extension will pick up any message where the "type" is zebra_print_label
and post the zpl
to the url
. That's all the magic there is.
Sadly, Zebra's printer only return 200 wether or not they were able to print. So there's no useful response we can provide as a reply to your message.
See for index.html a full working example.
This page is quite simple. You can reach it by simply clicking on the Zebra Icon of the extension.
You enter your printer's local IP address in the "Printer Address" field and your ZPL code into "ZPL here..." and hit "PRINT". Your printer should print right away. If not:
- Check the print server is enabled on your printer. This can be checked by entering your printer's IP address in your browser. If the printer's status page shows up, it's all good.
- Check your ZPL code. Quite often, there might be something wrong or missing in the ZPL code. Try if this code will print:
^XA^FO20,20^A0N,30,30^FDThis is a TEST^FS^XZ