[removed] Send raw text to printer - no server requests/method calls, able to work offline, purely clientside

前端 未结 5 1677
既然无缘
既然无缘 2020-12-07 18:14

My thorough research on the web provided me with a couple of ideas, but none of them seem to work correctly in my particular use case. Here is what I have:

1) Zebra

5条回答
  •  不知归路
    2020-12-07 18:34

    When printing to a Zebra printer, everything before ^XA and after ^XZ is ignored. The html tags around the zpl don't interfere.

    The only thing you must ensure is that you print RAW text to the printer.

    Use the build in windows Generic / Text Only driver for your Zebra printer. Instead of the zebra driver.

    • The normal zebra driver: renders the print job to a bitmap
      • result: a slow printed image of your zpl code.
    • The text only driver: sends the zpl code straight to the printer
      • result: a fast printed sticker, from zpl rendered on the printer

    Example on jsfiddle or on gist.run

    function printZpl(zpl) {
      var printWindow = window.open();
      printWindow.document.open('text/plain')
      printWindow.document.write(zpl);
      printWindow.document.close();
      printWindow.focus();
      printWindow.print();
      printWindow.close();
    }
    

    Tested in

    • Edge
    • Internet Explorer
    • Firefox

    Not working in:

    • Chrome
      • Chrome creates an image before sending it to the printer driver (https://productforums.google.com/forum/#!topic/chrome/GYf6iI42Ug4)

    Select the Generic / Text Only driver in your printer properties:

提交回复
热议问题