title: I can't get images to render within jsPDF using NativeScript
body: <p>Summary:</p>
  
  <p>Playground: <a href="https://play.nativescript.org/?template=play-vue&amp;id=pntfZD&amp;v=4" rel="nofollow noreferrer">https://play.nativescript.org/?template=play-vue&amp;id=pntfZD&amp;v=4</a></p>
  
  <p>I'm using <strong>NativeScript (VueJS)</strong> with the following plugins:</p>
  
  <ol>
  <li><a href="https://www.npmjs.com/package/nativescript-share-file" rel="nofollow noreferrer">nativescript-share-file</a></li>
  <li><a href="https://www.npmjs.com/package/jspdf" rel="nofollow noreferrer">jsPDF</a></li>
  <li><a href="https://github.com/mathiasbynens/base64" rel="nofollow noreferrer">base-64</a></li>
  </ol>
  
  <p>I'm generating a PDF on button click, and all is fine until I attempt to add an image. See <a href="https://parall.ax/products/jspdf/doc/symbols/jspdf.html" rel="nofollow noreferrer">here</a> for an example of how easy this is supposed to be.</p>
  
  <p>If I take my example image, which is just a black square and <code>base64encode</code> it using <a href="https://www.base64-image.de/" rel="nofollow noreferrer">this great resource</a> and drop the output into aforementioned link <a href="https://parall.ax/products/jspdf/doc/symbols/jspdf.html" rel="nofollow noreferrer">here</a> it works fine.</p>
  
  <p>Before I get to my code I also want to add that I'm <code>console.log(...)</code> my encoded string and paste that into the aforementioned site and it works fine.</p>
  
  <p>However, I'm missing something, because the image simply isn't showing up.</p>
  
  <p>Here's what got me started in this adventure: <a href="https://medium.com/@kumarandena/pdf-generation-in-nativescript-using-javascript-libraries-864ecf4e9a3a" rel="nofollow noreferrer">https://medium.com/@kumarandena/pdf-generation-in-nativescript-using-javascript-libraries-864ecf4e9a3a</a></p>
  
  <p>I'm also going to include some comments in my code which represent guidance and further questions.</p>
  
  <p>Here's the content of my method, comments and questions included:</p>
  
  <pre><code>const image = new imageSourceModule.ImageSource();
  image.fromFile("~/images/test.jpg").then(function(src) {
  // The "reallylong==" base64 value below is what I validated as working
  // on that demo site and even hard coded it to be sure
  
  var imgData = "data:image/jpeg;base64,/reallylong==";
  var doc = new jsPDF();
  doc.setFontSize(40);
  doc.text(35, 25, "Hello, world!");
  
  // Here is my function that I hope to ultimately work
  //doc.addImage("data:image/jpeg;base64," + image.toBase64String("jpg"), 'JPEG', 15, 40, 500, 500);                      
  
  // Here is the hard coded one from above
  doc.addImage(imgData, "JPEG", 15, 40, 180, 160);
  
  // This gets me the raw data that I'm going to save to file
  var datauristring = doc.output("datauristring").split(",")[1];
  
  const documents = fs.knownFolders.documents();
  const folder = documents.getFolder("testFolder");
  const file = folder.getFile("testFile.pdf");
  const data = base64.decode(datauristring);
  
  // For this data, I have tried various methods of encoding, decoding
  // using NSString, NSFile I think. I'm posting my question with the code in its current state.
  
  file.writeText(data)
    .then(result =&gt; {
      console.log("result", result);
      // result is always undefined but the PDF does save with text
  
      // I'm not sure why this is needed, but it fails otherwise.
      // More specifically, the share file dialogue opens but fails if I for example try to save the file somewhere. App doesn't crash, but iOS rejects it
      // I would expect the promise to resolve and a timeout not needed
      setTimeout(function() {
          var shareFile = new ShareFile();
              shareFile.open({
                  path: fs.path.join(documents.path + "/testFolder", "testFile.pdf"),
                  intentTitle: "Open text file with:",
                  rect: {
                      x: 110,
                      y: 110,
                      width: 0,
                      height: 0
                  },
                  options: false,
                  animated: true
              });
          }, 2000);
      }).catch(err =&gt; {
           // This is never reached
           console.log(err);
      });
  });
  </code></pre>
  
  <p>And finally, the output of my test opened after sending it to my MAC from phone: <a href="https://i.stack.imgur.com/6gFam.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6gFam.png" alt="pdf"></a></p>