if (!c || !c.width || !c.height) throw new Error('canvas'); cv = c; /* html2pdf would JPEG-encode the huge canvas again and store it in the PDF; hand it a tiny stand-in instead */ try { var t = document.createElement('canvas'); t.width = 40; t.height = Math.max(1, Math.round(40 * c.height / c.width)); if (this && this.prop && 'canvas' in this.prop) this.prop.canvas = t; } catch (e) {} }).toPdf().get('pdf').then(function(pdf){ var n = pdf.internal.getNumberOfPages(); while (n > 1) { pdf.deletePage(n); n--; } pdf.setPage(1); pdf.addImage(fitJpeg(cv), 'JPEG', 0, 0, 210, 297); }).save(); } bPdf.addEventListener('click', function(){ run(bPdf, function(){ return exportPdf(5).catch(function(){ return exportPdf(4); }).catch(function(){ return exportPdf(3); }).catch(function(){ return exportPdf(2); }); }); }); bImg.addEventListener('click', function(){ run(bImg, function(){ return html2pdf().set(opt).from(page).toCanvas().get('canvas').then(function(c){ return new Promise(function(res){ c.toBlob(function(blob){ var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'Digestion-Notes-A4.png'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(function(){ URL.revokeObjectURL(a.href); res(); }, 3000); }, 'image/png'); }); }); }); }); })();