I also ran into this problem, and Andrea's answer is only part of the solution. You really need to configure the pdfkit.js file. But first you need to do what Andrea did:
var myImage; var oReq = new XMLHttpRequest(); oReq.open("GET", "myimage.jpg", true); oReq.responseType = "arraybuffer"; oReq.onload = function(oEvent) { myImage = oReq.response;
As I said, you need to configure the pdfkit.js file. Roughly on line 2888:
PDFImage.open = function(src, label) { var data, match; if (Buffer.isBuffer(src)) { data = src; } else { //START NEW if (src instanceof ArrayBuffer) { data = new Buffer(new Uint8Array(src), 'object'); } else //END NEW if (match = /^data:.+;base64,(.*)$/.exec(src)) { data = new Buffer(match[1], 'base64'); } else { data = fs.readFileSync(src); if (!data) { return; } } }
Make sure you also enable blob-stream.js. I added an extra parameter after // START NEW, which takes care of the array buffers that come from XMLHttpRequests.
I don't know if this is the best solution, but it works.
source share