title: "Uncaught TypeError: Cannot read property 'embed' of undefined" when using custom image in the pdfMake pdf engine
body: <p>I am trying to download some reports in my application as pdf using <a href="http://pdfmake.org/playground.html" rel="nofollow">pdfMake pdf engine</a> and I adding a jpg logo image as,</p>
  
  <pre><code>var logoImg = 'sampleImage.jpg';
  var logoImage = "http://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg";
  if (logoImage) {
       var img = new Image();
       img.setAttribute('crossOrigin', 'anonymous');
       img.src = logoImage;
       var canvas = document.createElement("canvas");
       canvas.width = img.width;
       canvas.height = img.width;
       var ctx = canvas.getContext("2d");
       ctx.drawImage(img, 0, 0);
       logoImg = canvas.toDataURL("image/png");
   }
  </code></pre>
  
  <p>which is given in <a href="http://jsfiddle.net/mpsbhat/h5b9ycoo/" rel="nofollow">this fiddle</a>. But when I using a custom image, it gives <strong>Uncaught TypeError: Cannot read property 'embed' of undefined</strong> error when clicking the download button at the first time (check the console). When I run the ode once again, then the pdf will download correctly. So how can I solve the <strong>Uncaught TypeError</strong> error?</p>
  
  <p><strong>Edit</strong>: It will work correctly if I give the dataurl of image directly as given in <a href="http://jsfiddle.net/mpsbhat/h5b9ycoo/4/" rel="nofollow">this fiddle</a>. But I want to pass dataurl dynamically based on image link as given in the first fiddle above.</p>