-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmypdf.js
50 lines (37 loc) · 1.42 KB
/
mypdf.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var mypdf = (function mypdf() {
var self = {};
PDFJS.disableWorker = true;
self.load = function(url, callback) {
PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
var numPages = pdf.numPages;
var allText = '';
for(var i=0; i<= numPages; i++) {
(function(i) {
pdf.getPage(i).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
page.getTextContent().then(function (text) {
var extractedString = $.makeArray($(text.bidiTexts).map(function(element,value){return value.str})).join(' ');
allText += extractedString;
if(i == numPages) { // last
callback(allText);
}
/*
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
*/
});
});
})(i); // i
}
});
};
return self;
})()