尝试使用 print.js 在热敏打印机上打印

问题描述 投票:0回答:1

尝试打印 pdf 收据,但它在顶部和底部添加了空白。

const responseBlob = new Blob([pdfBlob], {
    type: 'application/pdf'
  });
  const fileURL = URL.createObjectURL(responseBlob);
  setPreview(false);
  // printJS(fileURL);
  printJS({
    type: 'pdf',
    printable: fileURL,
    honorMarginPadding: true,
    style: '@page { size: 80mm 50mm }'

  });

但我得到这样的打印。

PDF文件

解决方案: 使用 https://www.npmjs.com/package/react-to-print

代替 PrintJS
reactjs printing thermal-printer point-of-sale printjs
1个回答
0
投票

这应该可以解决问题 这些调整应有助于消除任何不需要的间距,并确保内容适合在指定页面尺寸为 80 毫米的单页内 打印JS({ 可打印:receiptRef.current, 类型:'html', 扫描样式:假, 风格:

@page { size: 80mm 100%; margin: 0; } body { margin: 0; } /* Additional styles to ensure no unwanted spacing */ html, body, #root, #root > div { margin: 0; width: 100%; height: 100%; overflow: hidden; }
, });

© www.soinside.com 2019 - 2024. All rights reserved.