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 = "

" + left + "
";

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 = "

My test row 1
My test row 2
"

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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐