eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
3.92k stars 1.37k forks source link

Multiple Page download found slowness while downloading #679

Open Srikantsurya opened 5 months ago

Srikantsurya commented 5 months ago

Hi,

If there are more than 100 page which consists of images, link and more styles, we getting time out issue in browser and completely that browser get hanged, using version of html2pdf 0.9.2, as html2pdf.bundle.js which we can make use of to get faster downloading of pdf.

Making use of this conversion of code:

const downloadPDF = (elements, options) => { let worker = html2pdf() .set(options) .from(elements[0])

if (elements.length > 1) {
    worker = worker.toPdf() // worker is now a jsPDF instance

    // add each element/page individually to the PDF render process
    elements.slice(1).forEach((element, index) => {

        worker = worker
            .get('pdf')
            .then(pdf => {
                pdf.addPage()
            })
            .from(element)
            .toContainer()
            .toCanvas()
            .toPdf()                  
    })
}