pdf-gold-digger/gd.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-07-23 01:05:11 +02:00
const GoldDigger = require('./src/GoldDigger');
const minimist = require('minimist');
const help = `
2019-07-22 22:46:05 +02:00
--file -f pdf file location (required)
--debug -d show debug information (optional - default false)
--output -o output format (optional - default text)
`
2019-07-22 22:46:05 +02:00
2019-07-22 22:48:58 +02:00
const supportedOutput = ['text', 'json'];
2019-07-22 22:46:05 +02:00
const ERR_INVALID_OUTPUT = `
Invalid output
Please specify one of those values : "${supportedOutput}"
`
// converts argument to boolean
const toBool = (val) => {
return val === 'true' || val === 1 || val === true;
}
const argv = minimist(process.argv.slice(2))
const fpath = argv['file'] || argv['f'];
let debug = argv['debug'] || argv['d'];
2019-07-22 22:46:05 +02:00
let output = argv['output'] || argv['o'] || 'text';
debug = toBool(debug);
2019-07-22 22:46:05 +02:00
if(output && supportedOutput.indexOf(output) < 0) {
console.error(ERR_INVALID_OUTPUT);
return;
}
if(!fpath) {
console.log(help);
console.log(argv);
return;
}
if(debug) console.log(fpath);
// configuration
const config = {};
config.paintFormXObject = false;
config.paintImageMaskXObject = false;
config.paintJpegXObject = false;
2019-07-22 22:46:05 +02:00
config.output = output;
const gd = new GoldDigger(config);
gd.dig(fpath, debug)