-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
46 lines (43 loc) · 1.27 KB
/
parser.js
File metadata and controls
46 lines (43 loc) · 1.27 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const PDFExtract = require('pdf.js-extract').PDFExtract;
const pdfExtract = new PDFExtract();
const options = {};
let contentPages = [];
let pagesPDF = [];
let titlePage = '';
let textPage = '';
let heightTitle;
let pagesArray = [];
pdfExtract.extract('sample.pdf', options, (err, data) => {
if (err) return console.log(err);
pagesPDF = data.pages;
for (let i=0; i < pagesPDF.length; i++){
contentPages = pagesPDF[i].content;
heightTitle = getMax(contentPages, "height");
for (let j=0; j < contentPages.length; j++){
var temp = contentPages[j].height;
if (temp >= heightTitle.height){
heightTitle.height = temp;
titlePage = titlePage + contentPages[j].str;
}else{
textPage = textPage + contentPages[j].str;
}
}
pagesArray.push({
"pageNumber" : i + 1,
"title" : titlePage,
"content" : textPage
});
heightTitle = 0;
textPage = '';
titlePage = '';
}
console.log(pagesArray);
});
function getMax(arr, prop){
var max;
for (var i=0 ; i<arr.length ; i++) {
if (max == null || parseInt(arr[i][prop]) > parseInt(max[prop]))
max = arr[i];
}
return max;
}