title: Let canvas.toDataUrl get the right dimension of image
body: <p>My dream is save the content of a div to pdf. Currently i'm using Html2pdf in this way:</p>
  
  <pre><code>function pdfFatt() {
          var idFatt = 1;
          var dataFatt = 1;
  
          var div = document.querySelector('.default_template_holder');
  
          if(div_stampa){
              html2canvas(div, {
                  onrendered: function (canvas) {
                      var imgData = canvas.toDataURL('image/jpeg');
                      var doc = new jsPDF();
                      doc.addImage(imgData, 'JPEG', 0, 0, 210, 297);
                      doc.save('fatt_'+idFatt+'_'+dataFatt+'.pdf');
                  }
              });
          }else{
  
          }
  }
  </code></pre>
  
  <p>The problem is resolution, infact all works but the resolution of image is really bad. (Screenshot 1).</p>
  
  <p>Surfing the net i have finded the solution, i will zoom the canvas! so my code is this</p>
  
  <pre><code>function pdfFatt() {
          var idFatt = 1;
          var dataFatt = 1;
  
          var scaleBy = 2;
          var w = 2480;
          var h = 3508;
          var div = document.querySelector('.default_template_holder');
          var canvas = document.createElement('canvas');
          canvas.width = w * scaleBy;
          canvas.height = h * scaleBy;
          canvas.style.width = w + 'px';
          canvas.style.height = h + 'px';
          var context = canvas.getContext('2d');
          context.scale(scaleBy, scaleBy);
  
          if(div_stampa){
              html2canvas(div, {
                  canvas:canvas,
                  onrendered: function (canvas) {
                      var imgData = canvas.toDataURL('image/jpeg');
                      var doc = new jsPDF();
                      doc.addImage(imgData, 'JPEG', 0, 0, 210, 297);
                      doc.save('fatt_'+idFatt+'_'+dataFatt+'.pdf');
                  }
              });
          }else{
  
          }
  }
  </code></pre>
  
  <p>The resolution now is ok, but the image not fit the canvas!! I need to add the parameter "canvas:canvas" on html2pdf function or it won't get the zooming. (Screenshot 2).</p>
  
  <p>Is there a way for obtaining the (screenshot 1) with the resolution of (Screenshot 2)?</p>
  
  <p>Thanks a lot.</p>
  
  <p><a href="https://imgur.com/a/mG6x3" rel="nofollow noreferrer">screenshot 1</a></p>
  
  <p><a href="https://imgur.com/a/9xsfK" rel="nofollow noreferrer">screenshot 2</a></p>
  
  <p>My code that resolves the issue is:</p>
  
  <pre><code>    function pdfFatt() {
     //selezione elementi nella visuale della fattura
     var menu = document.querySelector('.vertical_menu_area'); 
     var div = document.querySelector('.default_template_holder');
     var barra = document.querySelector('.fattura-strumenti');
  
     //controllo esistenza dei 3 elementi fondamentali
     if(div &amp;&amp; menu &amp;&amp; barra){
  
        //id e data fattura per nome pdf
        var idFatt = $j(".fattura-sub-intestazione input[name='id-fattura']").val();
        var dataFatt = $j(".fattura-sub-intestazione input[name='data-fattura']").val();
  
            //creazione canvas scalato x 2 per alta risoluzione
            var scaleBy = 2;
        var w_menu = menu.offsetWidth;
        var h_menu = menu.offsetHeight;
            var w_div = div.offsetWidth;
        var h_div = div.offsetHeight;
            var div_style = div.currentStyle || window.getComputedStyle(div);
            var mar_div_w = parseFloat(div_style.marginLeft);
            var mar_div_h = parseFloat(div_style.marginTop);
            var w_barra = barra.offsetWidth;
        var h_barra = barra.offsetHeight;
        var canvas = document.createElement('canvas');
            var context = canvas.getContext('2d');
            canvas.width = w_div * scaleBy;
        canvas.height = h_div * scaleBy;
            context.scale(scaleBy, scaleBy);
            context.translate(-w_menu-w_barra-mar_div_w-8,-mar_div_h);
        context.webkitImageSmoothingEnabled = true;
            context.mozImageSmoothingEnabled = true;
            context.imageSmoothingEnabled = true;
            context.imageSmoothingQuality = "high";
  
            //creazione pdf con script html2canvas
        html2canvas(div, {
           canvas:canvas,
           onrendered: function (canvas) {
              var imgData = canvas.toDataURL('image/jpeg', 1.0);
          var doc = new jsPDF();
          doc.addImage(imgData, 'JPEG', 0, 0, 210, 297);
          doc.save('fattura_'+idFatt+'_'+dataFatt+'.pdf');
            }
         });
     }else{
        alert("Impossibile salvare la fattura");
     }
  }
  </code></pre>