title: set pdf width and height according to image width and height
body: <p>I want to set the PDF width and height equal to the image width and height. But the image width and height is coming as 0.</p>
  
  <p>I also used <code>image.onload()</code> but that is not getting called.</p>
  
  <p>This is HTML:</p>
  
  <pre><code>&lt;span class="col-sm-3 padding0"&gt;
      &lt;button id="downloadModel" class="btn btn-md btn-default"
              style="height:100px;width: 210px" 
              ng-click="downloadWorkModel()"&gt;
            Download Work Model
      &lt;/button&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>$scope.downloadWorkModel= function(){
    var image = new Image();
    image.src = 'data:image/png;base64,'+$scope.workData.image;
    document.body.appendChild(image);
    console.log("image width: "+image.width); //coming 0
    console.log("image height: "+image.height); //coming 0
    var pdf = new jsPDF("l", "mm");
    pdf.addImage(image, 'png', 0, 0);
    pdf.save('workModel.pdf');
  };
  </code></pre>
  
  <p>NOTE:</p>
  
  <p>This doesn't work either (it doesn't goes inside onload)-</p>
  
  <pre><code>$scope.downloadWorkModel= function(){
      var image = new Image();
      var width, height;
      image.onload = function() {
          width= this.width;
          height= this.height;
      };
      image.src = 'data:image/png;base64,'+$scope.workData.image;
      document.body.appendChild(image);
      console.log("image width: "+image.width); //coming 0
      console.log("image height: "+image.height); //coming 0
      var pdf = new jsPDF("l", "mm", [width, height]);
      pdf.addImage(image, 'png', 0, 0);
      pdf.save('workModel.pdf');
  };
  </code></pre>
  
  <p>@mplungjan-</p>
  
  <p>After putting your code the download pdf content becomes too small to view-</p>
  
  <p><a href="https://i.stack.imgur.com/DGEqb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DGEqb.png" alt="enter image description here"></a></p>