Printing multiple labels in Browser Print

// Expert user has replied.
J Jeremy Deters 1 year 8 months ago
200 5 0

I am trying to print barcode labels for batches of items. My web API can return either a PDF document with all labels, or an array of label images.  I need to be able to print all labels in order from my web application (using BrowserPrint).

First I tried printing the labels as a PDF document and that works for Windows clients running the Windows version of BrowserPrint.  But the same application on android is printing blank labels.
Here is the method I am using:

function zebraPrintPdf(blob) {
    return selected_device.sendFile(
        blob
        , function () { console.log("PDF printed using Zebra BrowserPrint") }
        , function (error) { console.error("Failed to print PDF using Zebra BrowserPrint:" + error) }
    );
}



Again, this works for Windows, but for Android the labels all come out as blank.  I have inspected the payload to the 'write' method that is sent from the browser to BrowserPrint and the PDF is being included.  It even prints the correct number of blank labels (one for each page).  I think this is an issue with the Android BrowserPrint app.  I have an email in to the developers so hopefully they can point me in the right direction.  I'll update if I hear back from them.

Separately, I have tried printing the labels as images using the following ('labels' is an array of Uint8Arrays so it contains multiple images.  Blob type is 'images/bmp' because the images are in bmp format):

function zebraPrintMultipleLabels(labels, blobType) {

    var zebraPrinter = new Zebra.Printer(selected_device);
    var options = {};
    return zebraPrinter.isPrinterReady()
        .then(() => {
            for (const bytes of labels) {
                const blob = new Blob([bytes], { type: blobType });
                setTimeout(function() {
                    zebraPrinter.printImageAsLabel(blob,
                        options,
                        function () {
                            console.log("Image printed using Zebra BrowserPrint");
                        },
                        function (error) {
                            console.error("Failed to print Image using Zebra BrowserPrint:" + error);
                        });
                    }, 500);
                
            }
        }).catch((error) => {
            console.error(error);
            return false;
        });
}


This works (both on Windows and Android), but the labels don't seem to get printed in order, despite the images always being in the correct order. The order isn't even the same when printing the same 10 labels multiple times. Per the documentation, the 'Zebra.Printer.printImageAsLabel is supposed to use a queue to make sure that one command finishes before the next is sent.  But this doesn't seem to be working, even with the 500ms delay from the setTimeout method.

Does anyone have any suggestions or see where I am messing up (with either PDF or printing multiple labels)?

Please Register or Login to post a reply

5 Replies

O Omar Gordon

Did you ever find a solution I am having the same issue. I'm developing a web app and want to print batch labels from the clients end but no progress using Zebra Documentation 

J Jeremy Deters

I never found a fix for printing a PDF from Android.  As far as I can tell the Android version of the ZebraPrint app is broken.  I emailed Zebra developer support on two separate occasions but never received a response.

I was able to print multiple labels in the correct order.  I think the trick was to make it an async function and await the call to zebraPrinter.printImageAsLabel inside the foreach loop.  Awaiting the call to zebraPrinter.isPrinterReady also made sure my function did not return until all of the labels were printed.

async function zebraPrintMultipleLabels(labels, blobType) {
    var zebraPrinter = new Zebra.Printer(selected_device);
    var options = {};
    return await zebraPrinter.isPrinterReady()
        .then(async () => {
            for (let i = 0; i < labels.length; i++) {
                console.log("Printing image " + i.toString());
                const bytes = labels[i];
                const blob = new Blob([bytes], { type: blobType });
                await zebraPrinter.printImageAsLabel(blob, options).catch((error) => { console.error(`Image ${i.toString()} failed to print: ${error}`); });
                console.log(`Image ${i.toString()} printed`);
            }
            return true;
        }).catch((error) => {
            console.error(error);
            return false;
        });
}

Good luck
 

S Steven Si

"First I tried printing the labels as a PDF document and that works for Windows clients running the Windows version of BrowserPrint.  But the same application on android is printing blank labels."

Hi Jeremy,

Are you sure that the Browser Print for Android app is the latest version? There was a bug in the older version of the Browser Print for Android app, which caused the PDF print didn't work when sending a PDF file to a PDF Direct enabled printer. The bug has been fixed in the latest version of the Browser Print for Android app, which can be downloaded from the Browser Print Product Page

J Jeremy Deters

Hi Steven,

I downloaded whatever version was available from the browser print product page at that time (version 1.3.0.158). I had only been working on it a week or so before I posted my issue so that would have been 3-4 months ago or so. When was this new version made available?

I appreciate you letting me know there is a new version and that it should fix the issue.  I just wish I would have gotten a response sooner.  I have already re-worked all of my code to avoid using PDFs.

Is there a way to get notified of new updates (mailing list, rss feed, etc)?  Any plans to publish these apps to their respective stores (Android Play, Apple store, Windows store) so they will update automatically?

Thanks,

Jeremy

S Steven Si

Unfortunately, there is no mechanism in place to send out the notification. There is no plan to publish the Browser Print for Android app to Google Play. Because the Browser Print for Android app needs to be in sync with the Browser Print JavaScript libraries, which is recommended for maintaining the interoperability between the web app that uses the JavaScript libraries and the app on Android. As recommended, both the Browser Print JavaScript libraries and the Browser Print for Android app should be updated at the same time.

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