我正在开发一个销售点的web应用程序
我能够使用以下代码从网络中检测和打印
<html>
<body>
<textarea id="printContent"></textarea>
<input type="submit" onclick="connectAndPrint()" value="Print"/>
<P>Type text into box and click on submit button.
<script>
var device;
function setup(device) {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
}
function print() {
var string = document.getElementById("printContent").value + "\n";
var encoder = new TextEncoder();
var data = encoder.encode(string);
device.transferOut(1, data)
.catch(error => { console.log(error); })
}
function connectAndPrint() {
if (device == null) {
navigator.usb.requestDevice({ filters: [{}]})
.then(selectedDevice => {
device = selectedDevice;
console.log(device);
return setup(device);
})
.then(() => print())
.catch(error => { console.log(error); })
}
else
print();
}
navigator.usb.getDevices()
.then(devices => {
if (devices.length > 0) {
device = devices[0];
return setup(device);
}
})
.catch(error => { console.log(error); });
</script>
</body>
</html>
我的问题是我怎样才能发出命令来切断收据
注意事项:我使用齐达格软件向打印机添加了webusb认证,这改变了设备的签名,并使其在视图设备和打印机下的控制面板中不可见,因此我的打印机不在那里,并且无法在完成后进行自动剪切设置。
发布于 2022-06-27 06:01:40
要在打印后剪切,您需要将剪切命令添加到正在打印的文本的末尾。该命令将取决于您使用的打印机的类型。例如,如果您的打印机使用爱普生开发的ESC/POS命令集,您可以在这里找到有关裁剪命令的文档:
注意,这些命令可能需要将原始字节和ASCII控制代码放入发送到transferOut()调用中的设备的数据中。例如,列为"GS V 0“的命令将是"\x1D\x56\x00”,其中"GS“字符在十六进制中为0x1D,参数0为文字零字节,而不是数字"0”。
https://stackoverflow.com/questions/72761896
复制相似问题