electron-vite(react)print in portrait not working

qco9c6ql  于 8个月前  发布在  Electron
关注(0)|答案(1)|浏览(89)

我正在将我的一个旧的react-electron应用程序迁移到electron-vitedoc。此应用程序具有使用react-to-print实现的pos打印机功能。打印将以纵向方式进行。当我将其迁移到electron-vite时,打印功能开始变得奇怪。打印总是以横向方式进行。字体大小非常小。
旧电子版

"electron": "^22.0.0",

字符串
新电子版

"electron": "^25.6.0",


我不知道这是最新版本的electron还是electron-vite的问题。所以,我尝试更新我的打印选项和打印功能。
两种打印选项:

const printOptions = {
  silent: true,
  preview: true,
  printBackground: true,
  color: true,
  margin: {
    marginType: 'printableArea'
  },
  landscape: false,
  pagesPerSheet: 1,
  collate: false,
  copies: 1
}


打印机功能(新):

ipcMain.on('toMain', async (event, url) => {
  console.log('print invoked', url)
  const win = new BrowserWindow({ show: false, width: 302, nodeIntegration: true })

  win.loadURL(url)

  win.webContents.on('did-finish-load', () => {
    win.webContents.print(printOptions, (success, failureReason) => {
      console.log('Print Initiated in Main...')
      if (!success) console.log('ERR', failureReason)
    })
  })

  return true
})


在旧的应用程序中,我只使用show: false来创建浏览器窗口。我试图将近似的打印页面大小(80 mm)设置为width:302。根据文档,我在打印机选项中将打印横向设置为false(即使它是默认值)。
我知道电子pos打印机库。但它不能使用我有很多定制,使这是它的范围之外
我试着用landscape: false打印一个示例博客网页,它仍然给出了一个横向输出。

fivyi3re

fivyi3re1#

我花了一段时间才弄清楚这个问题与迁移到电子vite无关。实际上,v22.x.x以上的电子都有这个问题。
我所做的是降级电子开发依赖22.0.0这只是一个临时修复。

相关问题