5

I have a requirement. I have developed a webapp which has a HTML content. I want to print this content to Zebra Bluetooth Printer (IMZ320). Having gone through several blogs, I found that it is necessary to convert the HTML content to ZPL format in order to print.

  1. Can we convert HTML to ZPL & then send to print using plugin - https://github.com/LiamBateman/cordova-print

  2. Are there any plugins or libraries to achieve the HTML to ZPL conversion?

Thank you so much, Seyed Ismail.

Ismail MAC
  • 61
  • 2
  • 6

2 Answers2

0

I use a simple JS function for this. There is the first function that format text to display in HTML and the second that formats text for ZEBRA printing. I used CPCL in this example. But ZPL would work the same way.

 function sDisplayText(left) {                    
                var sResult = "<div>" + left + "</div>";
                return sResult;
            }




 function sPrintText(left) {                    
                var sResult = "T 7 0 30 30 " + left + '\r\n';
                return sResult;
            }

I assume that you get the content from a Database somewhere. You would have to use the function at the time you read the data and convert row by row:

Here is an example

var pStr = "";
var dStr = "";
pStr  = pStr  + sPrintText('My test row 1');
dStr = dStr + sDisplayText('My test row 1');

pStr  = pStr  + sPrintText('My test row 2');
dStr = dStr + sDisplayText('My test row 2');

This would result in:

dStr = "<div>My test row 1</div><div>My test row 2</div>"
pStr = "T 7 0 30 30 My test row 1\r\nT 7 0 30 30 My test row 2\r\n"

You can than take the content of "dStr" and display it on your browser and use "pStr" for the printer.

I would further suggest to use a plugin that understand ZEBRA and not just any print plugin.

Here is one that works with Android and Zebra

https://github.com/bstmedia/zbtprinter/

456q
  • 107
  • 11
0

A (commercial/non-free) HTML to ZPL API is available here: https://www.htmltozpl.com.

You can send an HTML string to the API, it converts the HTML into ZPL code, which can then be sent to a Zebra label printer.

danbtl
  • 84
  • 1
  • 10