-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 1.11 KB
/
index.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
27
28
29
30
31
32
33
34
35
36
const fs = require('fs');
const pdf = require('pdf-parse');
const basePath = "BASE_PATH";
function getAllPdfJSON(path) {
const ls = fs.readdirSync(path);
ls.map(file => {
const stats = fs.statSync(path + "/" + file);
if (file[0] === '.') return;
if (stats.isDirectory()) {
if (path.replace(basePath, "")) {
fs.mkdirSync(path.replace(basePath + "/", "") + "/" + file, { recursive: true });
}
getAllPdfJSON(path + "/" + file)
} else {
if (file.split('.').slice(-1)[0] === 'pdf') {
let dataBuffer = fs.readFileSync(path + "/" + file);
pdf(dataBuffer)
.then(function (data) {
fs.writeFileSync(path.replace(basePath + "/", "") + "/" + file.replace(".pdf", ".json"), JSON.stringify(data))
})
.catch(function (err) {
console.log("오류 발생 파일 : ", path + "/" + file);
console.log(err)
})
}
}
})
}
getAllPdfJSON(basePath);