0

I am trying to use jspdf and html2canvas for my project. It works great but if the page is large in size, it takes time to process after clicking the button to download the pdf. I would like to add a spinner as soon as the user clicks on the render PDF button. Though I have set the state for the loading property to true in react, the value is not rendered/displayed but it is displayed right before the pdf is downloaded.

Any thoughts ?

Code

printDocument() {
    const input = document.getElementById('container');
    this.setState({
        isDownloading: true
    });
    html2canvas(input)
      .then((canvas) => {
        const imgData = canvas.toDataURL('image/png');
        const pdf = new pdfConverter("p", "mm", "a4");
                    var width = pdf.internal.pageSize.width;    
                    var height = pdf.internal.pageSize.height;
                    pdf.addImage(imgData, 'JPEG', 0, 0,width,height);
                    pdf.save("download.pdf");
         this.setState({
            isDownloading: false
        })

      })
    ;
  }
Johnson Samuel
  • 2,046
  • 2
  • 18
  • 29

0 Answers0