-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
141 lines (128 loc) · 4.07 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<meta charset="utf-8">
<title>Конвертер PDF в JSON (Для реестра иноагентов)</title>
<style>
td {
white-space: pre;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<br>
<div class="container">
<div class="row">
<h3 align="center">Конвертер PDF в JSON (Для реестра иноагентов)</h3>
<div id="drop" class="mb-3">
<br>
<label for="pdf-file" class="form-label">Перетащите PDF сюда или нажмите</label>
<input class="form-control" type="file" id="pdf-file" />
</div>
</div>
<div class="row">
<div class="mb-3">
<label for="json-result" class="form-label">Результат</label>
<textarea class="form-control" id="json-result" style="width: 100%; height: 200px"></textarea>
</div>
</div>
</div>
<!--<div style="border:1px solid">
<div id="drop">
<span>Перетащите PDF сюда</span>
</div>
<span>или нажмите </span>
<input type="file" id="pdf-file" />
</div>
<h2>Результат</h2>
<textarea id="json-result" style="width: 100%; height: 200px"></textarea>-->
<script src="build/pdf.js"></script>
<script src="pdf-table-extractor.js"></script>
<script id="script">
var drop = document.getElementById('drop');
function handleDrop(e) {
$('#json-result').text('Обработка...');
e.stopPropagation();
e.preventDefault();
var files = e.dataTransfer.files;
var f = files[0];
{
var reader = new FileReader();
var name = f.name;
reader.onload = function(e) {
var data = e.target.result;
$('#json-result').text('Парсинг PDF...');
parse_content(data); //btoa(arr));
};
reader.readAsArrayBuffer(f);
}
}
function handleFile(e) {
$('#json-result').text('Обработка...');
var files = e.target.files;
var f = files[0];
{
var reader = new FileReader();
var name = f.name;
reader.onload = function(e) {
var data = e.target.result;
$('#json-result').text('Парсинг PDF...');
parse_content(data); //btoa(arr));
};
reader.readAsArrayBuffer(f);
}
}
document.getElementById('pdf-file').addEventListener('change', handleFile, false);
function handleDragover(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}
if(drop.addEventListener) {
drop.addEventListener('dragenter', handleDragover, false);
drop.addEventListener('dragover', handleDragover, false);
drop.addEventListener('drop', handleDrop, false);
}
pdf_table_extractor_progress = function(result){
$('#json-result').text("Парсинг PDF, прогресс: " + result.currentPages + " / " + result.numPages + " страниц");
};
var parse_content = function(content){
pdfjsLib.GlobalWorkerOptions.workerSrc = 'build/pdf.worker.js';
pdfjsLib.cMapUrl = 'https://mozilla.github.io/pdf.js/web/cmaps/';
pdfjsLib.cMapPacked = true;
var loadingTask = pdfjsLib.getDocument(content);
loadingTask.promise.then(pdf_table_extractor).then(function(result) {
// JSON output
let output = []
for(var j of result.pageTables) {
for(var i of j.tables) {
if(i[0] != "No п/п") {
let obj = {
id: i[0],
fullName: i[1],
dob: i[2],
ogrn: i[3],
inn: i[4],
regNum: i[5],
snils: i[6],
address: i[7],
resources: i[8],
members: i[9],
law: i[10],
dateIn: i[11],
datePubl: i[12],
dateOut: i[13]
}
output.push(obj)
}
}
}
document.getElementById('json-result').innerText = JSON.stringify(output);
});;
};
</script>
</body>
</html>