html2Canvas vs dom-to-image

Viewed 1167

Working on a project and the function below seems to take a great deal of time to process. I've seen html-to-image being talked up as better alternative although html2Canvas is clearly the most popular. Anyone used both and could confirm which one is faster?


  function saveVoucher(name) {
    const canvas = document.querySelector('#voucher');
    const myPromise = new Promise((resolve) => {
      setIsLoading(true);
      setTimeout(() => {
        resolve();
      }, 1000);
    });
    myPromise.then(() => {
      html2Canvas(canvas, {
        scrollY: -window.scrollY,
        scale: 2,
      }).then((canvas) => {
        setIsLoading(false);
        setIsOpen(true);
        let dataURL = canvas.toDataURL('image/jpeg', 2.0);
        const voucher = new jsPDF({
          unit: 'px',
          format: [185, 240],
        });
        voucher.addImage(dataURL, 'JPEG', 0, 0, 185, 240);
        voucher.save(`${name}.pdf`);
      });
    });
  }```
0 Answers
Related