我想使用带有 Laravel 和热敏打印机的电子应用程序打印账单。但是当我在电子应用程序中打印它时,它显示水平空白(红色框)
但是当我使用 ctrl+p 键从浏览器(不带电子)打印它时,它工作正常
我就是这样做的
const { BrowserWindow } = require('@electron/remote');
const options = {
silent: true,
printBackground: true,
color: false,
margins: {
marginType: 'none'
},
landscape: false,
pagesPerSheet: 1,
collate: false,
copies: 1,
header: 'bill',
footer: 'bill',
};
const win = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
const print = '{{ route('sale-invoice.bill', 'id') }}';
const url = print.replace('id', id);
win.loadURL(url);
win.webContents.on('did-finish-load', () => {
win.webContents.print({}, (success, failureReason) => {
if (!success) {
showAlert('error', 'Error Occurred', failureReason);
}
});
});
我尝试更改 dpi、pageSize 和边距选项,但没有任何效果
我也遇到同样的问题,我的解决方案是:
printWindow.webContents.print({
silent: true,
deviceName: "Microsoft Print to PDF",
margins: {
marginType: "none"
},
landscape: false,
dpi: {
horizontal: 600,
vertical: 600
},
pageSize: "A4"
}, () => {
});
dpi的值需要查看本地打印机的属性, 水平和垂直也可以只设置其中一个值。
html css 填充和边距设置为 0。
我一般都会尝试不设置dpi的解决方案,不知道朋友你解决了吗