我正在尝试将画布从 HRML2Canvas 转换为 PNG 图像,然后将其转换为 ZPL 图像以将 ZPL 命令发送到 Zebra 打印机,但我已经尝试过这个解决方案
但我不断收到此错误: Uncaught (in promise) TypeError: o(...) is not a function
请问有谁知道如何解决这个问题?
这是我的 JS 代码:
import { Controller } from "stimulus"
import html2canvas from 'html2canvas'
import imageToZ64 from 'zpl-image'
export default class extends Controller {
connect() {
$('#barcode-print-button').click((e) => {
this.printBarcode()
});
}
printBarcode() {
html2canvas(document.querySelector("#capture")).then(canvas => {
var Image = canvas.toDataURL("image/png");
let res = imageToZ64(Image);
let zpl = `^GFA,${res.length},${res.length},${res.rowlen},${res.z64}`;
var printWindow = window.open();
printWindow.document.open("")
printWindow.document.write(zpl);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
});
}
}