title: jsPDF with Cordova - Adding images
body: <p>I am trying to generate a PDF using the jsPDF library (<a href="https://github.com/MrRio/jsPDF" rel="noreferrer">https://github.com/MrRio/jsPDF</a>) from within a mobile Cordova app.   I am currently testing the app on an Android 4.0.4 device but it also needs to run on Windows mobile 8.  The text in the PDF document is shown correctly however any images are scrambled.  See image below</p>
  
  <p><img src="https://i.stack.imgur.com/GsWbi.png" alt="Image of PDF that was generated"></p>
  
  <p>I did find this page (<a href="https://coderwall.com/p/nc8hia" rel="noreferrer">https://coderwall.com/p/nc8hia</a>) that seemed to indicate there is a problem with jsPDF displaying images in Cordova (see comments) but the author never posted the follow-up.  Has anyone been able to use jsPDF with Cordova and properly add images to the generated PDF?  My code is below, any assistance or advice would be greatly appreciated.</p>
  
  <pre><code>function demoReceipt() {
      var img = new Image();
  
      img.onError = function() {
          alert('Cannot load image: "' + url + '"');
      };
      img.onload = function() {
          createPdf2(img);
      };
      img.src = 'img/testlogo.png';
  }
  
  
  
  function createPdf2(myLogo) {
      //  var doc = new jsPDF('p', 'pt', 'jontype');
  
      var doc = new jsPDF('p', 'pt', 'letter');
  
      doc.setProperties({
          title : 'Fueling Receipt',
          author : 'Jon Hoffman',
          creater : 'Jon Hoffman'
      });
  
      doc.addImage(myLogo, 'PNG', 5, 5, 140, 30);
      doc.setFontSize(12);
      doc.text(10, 40, 'Sample PDF receipt');
      doc.setFontSize(8);
      doc.text(10, 45, 'Smaller text - new');
  
      var pdfOutput = doc.output();
  
      //NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM
      //Requires  cordova plugin add org.apache.cordova.file
      console.log("file system...");
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
  
          console.log(fileSystem.name);
          console.log(fileSystem.root.name);
          console.log(fileSystem.root.fullPath);
  
          fileSystem.root.getDirectory("myPDFs", {
              create : true,
              exclusive : false
          }, function(dir) {
  
              fileSystem.root.getFile("myPDFs/test.pdf", {
                  create : true
              }, function(entry) {
                  var fileEntry = entry;
                  console.log(entry);
  
                  entry.createWriter(function(writer) {
                      writer.onwrite = function(evt) {
                          console.log("write success");
                      };
  
                      console.log("writing to file");
                      writer.write(pdfOutput);
                  }, function(error) {
                      console.log(error);
                  });
  
              }, function(error) {
                  console.log(error);
              });
          }, function(error) {
          });
      }, function(event) {
          console.log(evt.target.error.code);
      });
  }
  </code></pre>