-
Notifications
You must be signed in to change notification settings - Fork 1
/
jobs.html
87 lines (64 loc) · 2.05 KB
/
jobs.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
<!DOCTYPE html>
<html>
<head>
<title>IYCN - Green Jobs</title>
<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
</head>
<style>
canvas {
display: block;
margin: 0 auto;
width: 100%;
}
</style>
<script>
// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = './static/files/iycn-ce-jobs-1.pdf';
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];
// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
// Asynchronous download of PDFvar loadingTask = pdfjsLib.getDocument(url);
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(async function(pdf) {
var numPages = pdf.numPages;
var canvasArray = [];
// Loop through all pages
for (var i = 1; i <= numPages; i++) {
await pdf.getPage(i).then(async function(page) {
var scale = 1.5;
var viewport = page.getViewport({scale: scale});
// Prepare canvas using PDF page dimensions
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
var canvasContainer = document.createElement("div");
canvasContainer.style.display = "flex";
canvasContainer.style.justifyContent = "center";
canvasContainer.appendChild(canvas);
document.body.appendChild(canvasContainer);
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
await renderTask.promise.then(function () {
canvasArray.push(canvas);
});
});
}
// Append all canvas to the HTML in order
for (var j = 0; j < canvasArray.length; j++) {
document.body.appendChild(canvasArray[j]);
}
}, function (reason) {
// PDF loading error
console.error(reason);
});
</script>
<body>
</body>
</html>