简体   繁体   English

如何在电子中显示打印预览?

[英]How to show print preview in electron?

I am using Cordova-electron with ReactJS to build a desktop application.我正在使用 Cordova-electron 和ReactJS来构建桌面应用程序。 we need to implement print-preview in our application instead of showing the default system dialog for printing.我们需要在我们的应用程序中实现打印预览,而不是显示用于打印的默认系统对话框。 The community says there is no default way to achieve this in electron, we need to do it manually.社区说在电子中没有默认的方法来实现这一点,我们需要手动完成。 I used html2pdf.js,jsPDF to generate PDF from the client-side but none of these are giving the exact PDF we need, all have some alignment issues, font issues, and page-break issues, etc. please suggest me a proper solution for this issue.我使用 html2pdf.js,jsPDF 从客户端生成 PDF,但这些都没有提供我们需要的确切 PDF,都有一些对齐问题、字体问题和分页问题等。请建议我一个合适的解决方案对于这个问题。

I am attaching code to generate PDF by using html2pdf.js which I have used我正在使用我使用过的 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);
  })


  

不幸的是,电子没有打印预览,如果您想要打印预览,可以使用 nw.js 代替电子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM