0

I am working on an electron.js application where I am creating PDFs using jsPDF on the server side.

Its working as expected except the addimage property. It creates a rectangular black box in place of image in PDF.

global.PNG = require('png-js');
global.window = {document: {createElementNS: () => {return {}} }};
global.navigator = {};
global.atob = require('atob');

const jsPDF = require('jspdf');
let doc = new jsPDF();


let imgData = 'data:image/jpeg;base64,.................'
doc.addImage(imgData, 'PNG', 80, 10,50,15);

let data = doc.output();
fs.writeFileSync(folderPath, data);




delete global.window;
delete global.navigator;
delete global.btoa;

enter image description here

The same base64 image works in client side jsPDF, but not in node.js.

gauravatsit
  • 41
  • 1
  • 8
  • Possible duplicate of [Change html canvas black background to white background when creating jpg image from png image](https://stackoverflow.com/questions/32160098/change-html-canvas-black-background-to-white-background-when-creating-jpg-image) – pushkin Nov 27 '18 at 21:58
  • Maybe that's not the issue, but seems related: https://github.com/MrRio/jsPDF/issues/816 – pushkin Nov 27 '18 at 21:59

0 Answers0