pdf-gold-digger/gd.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

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