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