7 Replies Latest reply on Aug 21, 2017 3:25 PM by Javed Bashir

    Simplest Zebra Browser Print Example?

    Robert Davidson

      I have tried to simplify the DevDemo.js scripts for my purposes, but have not had any success. I am on an Internet Explorer 11 setup. The Zebra GK420d was successfully configured and works with the index.html sample. I try with the below function and nothing happens inside the BrowserPrint command:

      <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>

      <script type="text/javascript" src="js/BrowserPrint-1.0.4.min.js"></script>

      <script type="text/javascript">

      var format_start = "^XA^LL200^FO80,50^A0N36,36^FD";

      var format_end = "^FS^XZ";

      var txtToPrint = "Itza Miragul";

       

      function printTest() {

          testPresent(); // Added function to attached BrowserPrint-1.0.4.min.js to test if script could see it. This alert pops. Remove this line to use original BrowserPrint-1.0.4.min.js instead of attached version.

          BrowserPrint.getDefaultDevice('printer', function(printer)

              {

                  alert(printer.name); // This alert does not pop - why???

                  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

      }

      </script>

      I'm a novice to java so I probably managed to make some sort of syntax error, but I get no feedback about where it might be.

      Any help would be greatly appreciated.

       

      Best Regards,

       

      Robert

        • Re: Simplest Zebra Browser Print Example?
          Robin West

          Hi Robert, You are not checking if the default printer is set.  Browser Print does not use the OS default printer.  It has to be set by the user, or you have to give them the option to choose from connected printers.  BrowserPrint.getDefaultDevice runs asynchronously.

           

          <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>

          <script type="text/javascript" src="js/BrowserPrint-1.0.4.min.js"></script>

          <script type="text/javascript">

          var format_start = "^XA^LL200^FO80,50^A0N36,36^FD";

          var format_end = "^FS^XZ";

          var txtToPrint = "Itza Miragul";

           

          function printTest() {

              testPresent(); // Added function to attached BrowserPrint-1.0.4.min.js to test if script could see it. This alert pops. Remove this line to use original BrowserPrint-1.0.4.min.js instead of attached version.

              BrowserPrint.getDefaultDevice('printer', function(printer)

                  {

                      if((typeof printer != "undefined") && (printer.connection == undefined))

                      {

                          alert("No Printer Found");

                              // give option to choose printer

                      }

                      else{

                          alert(printer.name); // This alert does not pop - why???

                          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

          }

          </script>

            • Re: Simplest Zebra Browser Print Example?
              Robert Davidson

              Robin,

               

              Thank you for the explanation. I had thought that the printer the user chose as default printer on index.html would be sticky.

               

              In my case I know the printer is going to be the same each time and asking the user to reselect each time the page is loaded would adversely affect workflow. If possible, I'd like to specify the printer without calling getDefaultDevice.  Is there a getDevice(name) that could be used instead?

               

              Best Regards,

               

              Robert Davidson

                • Re: Simplest Zebra Browser Print Example?
                  Robin West

                  Hi Robert, you don't have to select every time and can set a default printer, but it is done using the running Browser Print app.

                  Right click the tray icon. and select Settings.

                  Then click the "Change" button to select the default printer.

                  The other way to handle this, if you know the printer you want every time, is to getLocalDevices to get the list of connected printers when the page loads.  You can then filter it based on the printer you want.

                   

                  This was designed more for websites where you as the developer do not know anything about your customer's printers, but the above options work.

                    • Re: Simplest Zebra Browser Print Example?
                      Robert Davidson

                      Default Zebra Browser Print app printer was set. I updated code to

                       

                      BrowserPrint.getDefaultDevice('printer', function(printer)
                          {
                              if((printer != null) && (printer.connection != undefined))
                              {
                                  alert(printer.name); // This alert does not pop - why???
                                  printer.send(format_start + txtToPrint + format_end);
                              }
                              else{
                                 alert("No Printer Found");
                              }
                         },
                          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.");
                          }
                      );

                       

                      However none of the alerts inside the BrowserPrint line pop. Did you test it and have it work for you?

                        • Re: Simplest Zebra Browser Print Example?
                          Robert Davidson

                          I also added this to the script:

                          BrowserPrint.getLocalDevices(function(printers)
                             {
                             if (printers != undefined)
                             {
                             for(var i = 0; i < printers.length; i++)
                             {
                             if (printers[i].connection == 'usb')
                             {
                             alert(printers[i].name);
                             }
                             }
                             }
                             else{
                             alert("No Zebra Printers could be found!");
                             }
                             }, undefined, 'printer');

                           

                          But none of the alerts popped in getLocalDevices either.

                      • Re: Simplest Zebra Browser Print Example?
                        Robin West

                        Also, Note as far as the stickyness of a selected printer goes, remember that when you switch from page to page the DOM is reset and all your variables go away.  I'm not 100 percent sure if you save the selected printer in localStorage that you could use it again.  I'll check on that on Monday if you want.

                    • Re: Simplest Zebra Browser Print Example?
                      Javed Bashir

                      Is there a way to fix the insecure https://localhost9101 issue when printing from the web. We've got the BrowserPrint utility to print from a public website, but when the print function is called it throws up this insecure site.

                       

                       

                      2017-08-21_23-13-55.jpg