Cannot read property '0' of undefined when parsing pdf
Stack trace:
(while reading XRef): TypeError: Cannot read property '0' of undefined
XRefParseException
at XRefParseExceptionClosure (eval at <anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:6), <anonymous>:379:34)
at eval (eval at <anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:6), <anonymous>:384:3)
at Object.<anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/pdfparser.js:8:10)
Error
at InvalidPDFExceptionClosure (eval at <anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:6), <anonymous>:330:35)
at eval (eval at <anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:6), <anonymous>:334:3)
at Object.<anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/lib/pdf.js:64:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/petterroea/Dropbox/div-projects/bot/node_modules/pdf2json/pdfparser.js:8:10)
Code:
var pdfParser = new PDFParser();
console.log("Downloaded timeschedule.");
pdfParser.on("pdfParser_dataReady", pdfData => {
console.log("Got pdf data");
console.log(pdfData);
});
pdfParser.loadPDF("temp.pdf");
Node -v:
v5.11.1
It might be a poorly generated pdf(2000's consultant work apparently), but other readers support it fine.
the testing pdf is downloaded and save in test/pdf/misc/ as i64_schedule_generator.pdf. Then run cmd line: node pdf2json.js -f test/pdf/misc/i64_schedule_generator.pdf -o test/target/misc/
it parses then writes out i64_schedule_generator.json correctly.
node -v: v4.4.0
I will re-test with my environment at home and re-try.
@petterroea did you figure out what the issue was? I'm getting the same error
Hello, I am facing the same issue with node v10.8.0 and pdf2json 1.1.7.
I am using pdf2json to parse multiple PDFs but when I run the script, some of them (not always the same) get the (while reading XRef): TypeError: Cannot read property '0' of undefined error
Stack trace same as @petterroea 's
Hello, I am facing the same issue with node
v10.8.0and pdf2json1.1.7. I am using pdf2json to parse multiple PDFs but when I run the script, some of them (not always the same) get the(while reading XRef): TypeError: Cannot read property '0' of undefinederrorStack trace same as @petterroea 's
facing same error
I second this; I got this error randomly. Same pdf worked fine on the next iteration (version: ^1.2.1)
This issue has grown up with me since high school and I'm now a professional software engineer, haha! Thanks for fixing and closing the issue, reminding me of it! :D