title: NodeJS jsPDF addImage gives an error when adding a PNG
body: <p>I am not entirely sure what is wrong. I am just trying to add a PNG image and this library refuses to work. I have had to do way too much just to get this library to still not work and I may have to move to another library, but before I do that I wanted to ask the question. My code is below.  </p>
  
  <pre><code>import * as fs from 'fs';
  import * as PNG from 'png-js';
  import * as atob from 'atob';
  import * as btoa from 'btoa';
  
  export interface Global extends NodeJS.Global {
      window: any;
      navigator: any;
      btoa: any;
      atob: any;
      PNG: any;
  }
  
  declare var global: Global;
  global.window = {document: {createElementNS: () =&gt; ({})}};
  global.navigator = {};
  global.btoa = btoa;
  global.atob = atob;
  global.PNG = PNG;
  
  import * as jsPDF from 'jspdf/dist/jspdf.node.debug';
  
  export class PDFGenerator {
  
      constructor() {
      }
  
      public async generatePDF(): void {
         const doc = new jsPDF('l', 'pt', 'a3');
         const image = fs.readFileSync('src/assets/images/logo.png');
         const width = doc.internal.pageSize.getWidth();
         doc.addImage(image.toString('base64'), 'PNG', (width / 2), 0);
         const data = doc.output();
         fs.writeFileSync(`public/reports/test-report.pdf`, data);
  
     }
  }
  </code></pre>
  
  <p>When I run this, the PDF is printed with only text and I get <code>error: Cannot read property 'buffer' of undefined</code> and <code>fn is not a function</code>.  I have traced this to a function called <code>decodePixels().buffer</code>. This looks like a bug in the code, but since nobody seems to have complained about it, I assume I'm doing something wrong.  Any type of help would really be appreciated.</p>