我无法使用 pdf2json 将 pdf 转换为 json 格式。我想通过nodejs使用pdf2json库将pdf文件转换为json格式。但是,我为json指定的目录中没有json文件,我放一个空的json文件时它并没有过期。当我在调试模式下运行我的代码时,它会输出以下日志。我该怎么做才能保存为json?
我遵循这些步骤; https://github.com/modesty/pdf2json
控制台日志消息
/Desktop/nodejs-pdf-parse/app.js
Debugger listening on ws://127.0.0.1:45843/bb0e57e8-b28d-4652-81f8-2cba00f4372b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
节点
let fs = require('fs'), PDFParser = require("pdf2json");
let pdfParser = new PDFParser(this, 1);
try {
pdfParser.loadPDF("/Desktop/nodejs-pdf-parse/pdf/Paycheck-Protection.pdf");
}catch (e) {
console.log(e)
}
pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile("/Desktop/nodejs-pdf-parse/parsed-json/parsed.json", JSON.stringify(pdfData));
});
运行:节点 app.js
fs.js:148
throw new ERR_INVALID_CALLBACK(cb);
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
at maybeCallback (fs.js:148:9)
at Object.writeFile (fs.js:1298:14)
at PdfParser.<anonymous> (/home/mutlueren/Desktop/nodejs-pdf-parse/app.js:7:8)
at PdfParser.emit (events.js:315:20)
at PdfParser._onPDFJSParseDataReady (/home/mutlueren/Desktop/nodejs-pdf-parse/node_modules/pdf2json/pdfparser.js:25:9)
at cls.emit (events.js:315:20)
at /home/mutlueren/Desktop/nodejs-pdf-parse/node_modules/pdf2json/lib/pdf.js:250:38
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
code: 'ERR_INVALID_CALLBACK'
}
忽然笑
相关分类