尝试打印 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文件
代替 PrintJS这应该可以解决问题 这些调整应有助于消除任何不需要的间距,并确保内容适合在指定页面尺寸为 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; }
,
});