forked from ronnywang/pdf-table-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-cmd.js
27 lines (20 loc) · 852 Bytes
/
parse-cmd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Ex: node parse-cmd.js samples/pta_10229_131308_94274.pdf
var fs = require('fs');
Image = function(){ };
// HACK few hacks to let PDF.js be loaded not as a module in global space.
require('./pdf.js/examples/node/domstubs.js');
require('./pdf-table-extractor.js');
// Run `gulp dist` to generate 'pdfjs-dist' npm package files.
PDFJS = require('./pdf.js/build/dist');
PDFJS.cMapUrl = './pdf.js/build/generic/web/cmaps/';
PDFJS.cMapPacked = true;
// Loading file from file system into typed array
var pdfPath = process.argv[2];
var data = new Uint8Array(fs.readFileSync(pdfPath));
// Will be using promises to load document, pages and misc data instead of
// callback.
PDFJS.getDocument(data).then(pdf_table_extractor).then(function (result) {
console.log(JSON.stringify(result));
}, function (err) {
console.error('Error: ' + err);
});