title: How to fit an image in the center of a page using jsPDF?
body: <p>Using html2canvas &amp; jsPDF, I'm trying to print an entire <code>DIV</code> I have on my screen and I've gotten this far:</p>
  
  <pre class="lang-js prettyprint-override"><code>const printAsPdf = () =&gt; {
    html2canvas(pageElement.current, {
      useCORS: true,
      allowTaint: true,
      scrollY: -window.scrollY,
    }).then(canvas =&gt; {
      const image = canvas.toDataURL('image/jpeg', 1.0);
      const doc = new jsPDF('p', 'px', 'a4');
      const pageWidth = doc.internal.pageSize.getWidth();
      const pageHeight = doc.internal.pageSize.getHeight();
  
      const widthRatio = pageWidth / canvas.width;
      const heightRatio = pageHeight / canvas.height;
      const ratio = widthRatio &gt; heightRatio ? heightRatio : widthRatio;
  
      const canvasWidth = canvas.width * ratio;
      const canvasHeight = canvas.height * ratio;
  
      doc.addImage(image, 'JPEG', 0, 0, canvasWidth, canvasHeight);
      doc.output('dataurlnewwindow');
    });
  };
  </code></pre>
  
  <p>This fills up the page with the image/canvas of my choosing. But I am not able to align the image dead center on the page.</p>