foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.89k stars 1.15k forks source link

Cannot read property 'readFileSync' of undefined #604

Open Davidzhu001 opened 7 years ago

Davidzhu001 commented 7 years ago

Uncaught TypeError: Cannot read property 'readFileSync' of undefinedPDFImage.open @ image.js:33image @ images.js:28(anonymous function) @ pdfkit.js:50270.blob-stream @ pdfkit.js:67s @ _prelude.js:1(anonymous function) @ _prelude.js:1(anonymous function) @ fake_f103dc0.js:6268.../../semantic/dist/semantic.min.js @ fake_f103dc0.js:7s @ _prelude.js:1e @ _prelude.js:1(anonymous function) @ _prelude.js:1

MutterPedro commented 7 years ago

I am having the same problem, when I try to insert an image to the PDF, the same message appears, but I have already debugged the whole code, the src is not undefined, and the path is valid.

Code: const imgPath = 'http://behive.wpengine.com/wp-content/uploads/2017/04/LoadIcon.png'; doc.image(imgPath, 0, 15, {width: 300}).font('Helvetica', 20).text('behive', 0, 0);

alafr commented 7 years ago

It's not possible to open an image in PDFKit directly from the internet. You have to download it as an ArrayBuffer : #491 #410

MutterPedro commented 7 years ago

Thanks, but now I'm getting this error:

Uncaught Error: Unknown image format.

On debugger, the data converted from buffer is: data: Uint8Array[14] 0: 80 1:78 2:71 3:95 4:98 5:101 6:104 7:105 8:118 9:101 10:46 11:80 12:78 13:71