-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathparse-cmd.js
More file actions
26 lines (19 loc) · 813 Bytes
/
parse-cmd.js
File metadata and controls
26 lines (19 loc) · 813 Bytes
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
// Ex: node parse-cmd.js samples/pta_10229_131308_94274.pdf
var fs = require('fs');
const canvas = require('canvas');
global.DOMMatrix = canvas.DOMMatrix;
global.pdfjsLib = require('pdfjs-dist/legacy/build/pdf.mjs');
pdfjsLib.cMapUrl = 'pdfjs-dist/cmaps/';
pdfjsLib.cMapPacked = true;
require('./pdf-table-extractor.js');
// 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.
pdfjsLib.getDocument(data).promise.then(pdf_table_extractor).then(function (result) {
console.log(JSON.stringify(result));
// fs.writeFileSync('output.json', JSON.stringify(result));
}, function (err) {
console.error('Error: ' + err, err.stack);
});