-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Why is the code using Buffer when running inside a browser?
When creating a PDFDocument I get the following error in the browser console:
pdfkit.js:441 Uncaught (in promise) ReferenceError: Buffer is not defined
at wordArrayToBuffer2 (pdfkit.js:441:3)
at Function.generateFileID (pdfkit.js:454:12)
at new PDFDocument2 (pdfkit.js:38748:29)
Seems to be coming from the module pdfkit.js
I am using version 3.4.4 of the library.
I am trying to generate pdf in the browser. Isn't Buffer only available in Node? Why is the code using Buffer when running inside a browser?
Using Chrome Browser: Version 124.0.6367.208 (Official Build) (arm64)
Workaround:
I installed buffer (npm install buffer) and then added the following to my index.js file:
window.Buffer = window.Buffer || require("buffer").Buffer;