Erster Commit
This commit is contained in:
29
extract-pdf.js
Normal file
29
extract-pdf.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const fs = require('fs');
|
||||
const PDFParser = require("pdf2json");
|
||||
|
||||
function extract(fileIn, fileOut) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const pdfParser = new PDFParser(this, 1);
|
||||
|
||||
pdfParser.on("pdfParser_dataError", errData => reject(errData.parserError));
|
||||
pdfParser.on("pdfParser_dataReady", pdfData => {
|
||||
fs.writeFileSync(fileOut, pdfParser.getRawTextContent());
|
||||
console.log(`Extracted: ${fileOut}`);
|
||||
resolve();
|
||||
});
|
||||
|
||||
pdfParser.loadPDF(fileIn);
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length >= 2) {
|
||||
await extract(args[0], args[1]);
|
||||
} else {
|
||||
await extract('./docs/ZF Global DESADV 1.3.9 EN Examples.pdf', './docs/zf_examples.txt');
|
||||
await extract('./docs/ZF Global DESADV 1.3.9 EN.pdf', './docs/zf_guideline.txt');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user