2 Replies Latest reply on Sep 24, 2018 10:03 AM by ad0bf79a-239a-48b4-91c0-4ff198fd209b

    Example of PDF file printing using Zebra Browser Print SDK

    ad0bf79a-239a-48b4-91c0-4ff198fd209b

      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.

        • Re: Example of PDF file printing using Zebra Browser Print SDK
          Robin West

          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.

            • Re: Example of PDF file printing using Zebra Browser Print SDK
              ad0bf79a-239a-48b4-91c0-4ff198fd209b

              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.