Example of PDF file printing using Zebra Browser Print SDK

A Anders Bilfeldt 3 years 7 months ago
783 2 0

Hi

Does anyone have an example of how to print a PDF file using the Zebra Browser Print SDK?

We have a simple test that is capable of printing a text using:
function printTest() {    BrowserPrint.getDefaultDevice('printer', function(printer)        {            if((typeof printer != "undefined") && (printer.connection == undefined))            {                alert("No default printer found. " + "Setup a default printer in Zebra Browser Print.");                    // give option to choose printer            }            else{                alert("Printer name: " + printer.name);                printer.send(format_start + txtToPrint + format_end);            }        },        function(error_response)        {            // This alert doesn't pop either            alert("An error occured while attempting to connect to your Zebra Printer. " +                "You may not have Zebra Browser Print installed, or it may not be running. " +                "Install Zebra Browser Print, or start the Zebra Browser Print Service, and try again.");        }    );    alert("After BrowserPrint"); //This alert pops up immediately instead of waiting}
But the alert "Ater BrowserPrint" is shown immediately (and then the error), and we have no idea how to print a PDF file instead of raw text.

Thanks.

Please Register or Login to post a reply

2 Replies

E Efkan YILMAZ

Hi Anders, Did you set the default printer in Browser Print?  This is separate from the Windows Default printer.
getDefaultDevice is asynchronous, so the "After BrowserPrint" will almost always show up before the default device is found.
Past that, is the printer capable of taking PDF files?  You need special software installed on the printer to print PDFs directly.
Once you have determined that, I would recommend using the sendUrl() function to send the PDF.

A Anders Bilfeldt

Hi Robin

It makes sense that the "After BrowserPrint" alert is shown before the job is printed, since getDefaultDevice is asynchronous.

Regarding PDF files:  Most of our users use something like a Zebra GK420d, but some use others. I have come to the conclusion now, that we can only send ZPL II or PNG|BMP|JPEG directly to the printer with the Browser Print SDK.

My current workaround is simply converting the PDF to PNG and then trying to send the PNG image to the printer. But this is of cause not ideal.

Do you have an example of sending a base 64 encoded PNG (or a HTML5 canvas element) to the printer using the Browser Print SDK?

Thanks.

CONTACT
Can’t find what you’re looking for?