I'm using PDFMake in the browser and recently updated from 0.1.53 to 0.1.55 only to discover that, once built and minified for production, PDF generation attempts were failing and throwing the following error:
RangeError: "Trying to access beyond buffer length"
L http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:9
readUInt32BE http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:9
i http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:9
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
A http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
A http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
A http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
A http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
s http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
A http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:33
_createDoc http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
getBuffer http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
getBlob http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
_openPdf http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
open http://localhost:8080/js/asyncVendors~reportActions.147b16f56deef78b1f89.js:16
createPdf http://localhost:8080/js/reportActions.70ffa8c5a107efb783fd.js:1
click http://localhost:8080/js/reportActions.70ffa8c5a107efb783fd.js:1
nt http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
n http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
nt http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
$emit http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
onClick http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:26
nt http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
n http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
_wrapper http://localhost:8080/js/initVendors~main.372d53e485683e2a59ee.js:57
reportActions.70ffa8c5a107efb783fd.js:1:13766
Frustratingly, I can't replicate this when running unminified in dev. The error seems to stem somewhere within the feross/buffer package, but that's about as much as I can discern. The error persisted with 0.1.56, I haven't tried 0.1.54 yet. The application creates a PDF with an image, a title, and a table.
I'm going to continue to investigate as far as I can- I appreciate that this is a bit esoteric. Thank you for this library, it's otherwise been really great and easy to work with and has helped us create a lot of value for our customers.
And pdfmake version 0.1.54 works without error or not?
I have the same issue using 0.1.56 and 0.1.57
Can you test with version 0.1.54?
I was having the same issue with 0.1.56. Just rolled back to 0.1.54 and it appears to work again.
In version 0.1.55 is upgraded pdfkit to 0.9.1 and webpack from version from 3 to 4.
And I don't know how simulate this issue. How to simulate it?
I am using pdfMake inside a react app built with Create-React-App. I just built a basic repro here:
https://github.com/Dannzzor/pdfmake-bug-repro
assuming using yarn, if you yarn install, then you can run yarn start and the app will run the non-minified version on localhost:3000. it should load with a download pdf button, which should work.
Next, if you run yarn build it will create a minified build under the /build directory. after that run yarn server and it should host the minified build at localhost:3001, now the download pdf button will not work.
Hopefully that helps!
I'll look at it
I am using pdfMake inside a react app built with Create-React-App. I just built a basic repro here:
https://github.com/Dannzzor/pdfmake-bug-repro
I changed line https://github.com/Dannzzor/pdfmake-bug-repro/blob/master/src/App.js#L2 to import 'pdfmake/build/pdfmake' instead of 'pdfmake/build/pdfmake.min' and worked both in production and development build.
Can you confirm?
@i-hardy are importing the minified build of pdfmake?
@blikblum Yes I'm importing the minified build.
@blikblum Yep, tried that and it seems to work perfectly now! Thanks!
For the record. Tried to use terser plugin in minified build with no luck. Now fails with the following error:
RangeError: offset is outside the bounds of the DataView
Out of ideas for now. I would just document that if is importing from webpack do not use the minified build. There's no loss for user since will be minified anyway in production build
Fixed by commit https://github.com/bpampuch/pdfmake/commit/27d4b1c0646d888f78c94ffe37aea1981427a999 (in 0.1 branch) and https://github.com/bpampuch/pdfmake/commit/8ce24e068dc636511871c38bd97b99c3ecf412b7 (in master)
Most helpful comment
I changed line https://github.com/Dannzzor/pdfmake-bug-repro/blob/master/src/App.js#L2 to import 'pdfmake/build/pdfmake' instead of 'pdfmake/build/pdfmake.min' and worked both in production and development build.
Can you confirm?
@i-hardy are importing the minified build of pdfmake?