看......
我在linux机器上安装了服务器(RHEL 7 + PHP)。我有一个名为&#34的服务器;打印机" acessible by:192.168.0.48/Printer。
我的服务器上有一个页面php,它在这个位置创建一个带有一些ZPL LANGUAGE的文件
' \打印机\文件\'
可以通过"将生成的文件发送到side-client的打印机。 window.open()" ?
或者例如,获取此文件的内容并插入此函数?
<script type="text/javascript">
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();
}
</script>
答案 0 :(得分:0)
您可以在函数调用时将字符串传递给encodeURIComponent()
,并在打开的.textContent
处将字符串设置为<pre>
元素的window
,以保留print()
处的新行字符调用
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="print">Print file</button>
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open(`data:text/html,<!DOCTYPE html><html><body><pre>${zpl}</pre><script>print();<\/script></body></html>`);
printWindow.focus();
}
var zpl = `^XA
^FXTest ZPL
^FS
^FO50,100
^A0N,89
^FDHello ZPL
^FS
^XZ`;
document.getElementById("print")
.onclick = function() {
printZpl(encodeURIComponent(zpl))
};
</script>
</body>
</html>