reactjs - how to print base64 image by TSPL command in react - Stack Overflow

i have zebra printer and connect to this by webUsb and command to print by tsplCommandBut the printer

i have zebra printer and connect to this by webUsb and command to print by tsplCommand But the printer output prints in black stripes. how can i fix that

  const devices = await navigator.usb.getDevices();
  const printer = devices.find(
    (item: any) => item.manufacturerName === "IDPrinter",
  );
  const device = await navigator.usb.requestDevice({
    filters: [
      { vendorId: printer?.vendorId, productId: printer?.productId },
    ],
  });
  const imageData = canvas.toDataURL("image/png");
  const response = await fetch(imageData);
  const blob = await response.blob();
  const arrayBuffer = await blob.arrayBuffer();
  const byteArray = new Uint8Array(arrayBuffer);

  const tsplCommand = `
  SIZE 100 mm, 50 mm
  GAP 2 mm, 0 mm
  DIRECTION 1
  CLS
  BITMAP 10,10,${canvas.width / 8},${canvas.height},1,${byteArray}
  PRINT 1,1
  `;

  const encoder = new TextEncoder();
  const data = encoder.encode(tsplCommand);

  await device.open();
  await device.selectConfiguration(1);
  await device.claimInterface(0);

  await printer.transferOut(1, data);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744201772a4562913.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信