2

I am using Cordova-electron with ReactJS to build a desktop application. 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.

I am attaching code to generate PDF by using html2pdf.js which I have used

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);
  })


  
Nishil S.B
  • 69
  • 1
  • 11

1 Answers1

0

Unfortunately, the electron does not have a print preview, you can use nw.js instead of the electron if you want a print preview

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 25 '21 at 08:57