【问题标题】:How to show print preview in electron?如何在电子中显示打印预览?
【发布时间】:2021-11-27 05:28:47
【问题描述】:

我正在使用带有 ReactJS 的 Cordova-electron 来构建桌面应用程序。我们需要在我们的应用程序中实现打印预览,而不是显示用于打印的默认系统对话框。 社区说在电子中没有默认的方法来实现这一点,我们需要手动完成。我使用 html2pdf.js,jsPDF 从客户端生成 PDF,但这些都没有提供我们需要的确切 PDF,都有一些对齐问题、字体问题和分页问题等。请建议我一个合适的解决方案对于这个问题。

我正在附加代码以使用我使用过的 html2pdf.js 生成 PDF

var opt = {
  margin: 1,
  filename: 'myfile.pdf',
  image: { type: 'jpeg', quality: 0.98 },
  html2canvas: { scale: 1, logging: true, width: '1024', dpi: 100, letterRendering: true },
  jsPDF: { unit: 'mm', orientation: 'portrait', format: 'a4' },
  pagebreak: { after: '.page-break' }
}
 var worker = html2pdf().set(opt).from(componentRef.current).to('pdf').output('blob').then(d => {
    console.log('pdf-file', d);
    var blob = new Blob([d], { type: "application/pdf" });
    console.log('Blob-pdf', blob);


    var url = URL.createObjectURL(blob);

    var printWindow = window.open(url, '', 'width=800,height=500');

  }).catch(d => {
    console.error('error in PDF generation', d);
  })


  

【问题讨论】:

    标签: javascript reactjs cordova electron electron-packager


    【解决方案1】:

    很遗憾,electron 没有打印预览,如果你想要打印预览,可以使用 nw.js 代替 electron

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2013-10-19
    • 2016-06-13
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    相关资源
    最近更新 更多