2019-07-23 01:05:11 +02:00
|
|
|
const GoldDigger = require('./src/GoldDigger');
|
2019-07-22 20:58:24 +02:00
|
|
|
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 20:58:24 +02:00
|
|
|
`
|
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}"
|
|
|
|
`
|
|
|
|
|
2019-07-22 20:58:24 +02:00
|
|
|
// 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';
|
2019-07-22 20:58:24 +02:00
|
|
|
debug = toBool(debug);
|
2019-07-22 22:46:05 +02:00
|
|
|
if(output && supportedOutput.indexOf(output) < 0) {
|
|
|
|
console.error(ERR_INVALID_OUTPUT);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-22 20:58:24 +02:00
|
|
|
if(!fpath) {
|
|
|
|
console.log(help);
|
|
|
|
console.log(argv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(debug) console.log(fpath);
|
2019-07-22 21:26:01 +02:00
|
|
|
|
|
|
|
// configuration
|
|
|
|
const config = {};
|
|
|
|
config.paintFormXObject = false;
|
|
|
|
config.paintImageMaskXObject = false;
|
|
|
|
config.paintJpegXObject = false;
|
2019-07-22 22:46:05 +02:00
|
|
|
config.output = output;
|
2019-07-22 21:26:01 +02:00
|
|
|
|
|
|
|
const gd = new GoldDigger(config);
|
2019-07-22 20:58:24 +02:00
|
|
|
gd.dig(fpath, debug)
|