-
Notifications
You must be signed in to change notification settings - Fork 0
/
Examplepdf.html
62 lines (56 loc) · 2.15 KB
/
Examplepdf.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF Viewer</title>
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
<style>
#viewerContainer {
width: 100%;
height: 600px;
overflow-x: auto; /* Allows horizontal scrolling */
white-space: nowrap; /* Makes the canvas align horizontally */
}
canvas {
display: inline-block;
}
</style>
</head>
<body>
<div id="viewerContainer">
<canvas id="the-canvas"></canvas>
</div>
<script>
var url = 'https://drive.google.com/uc?export=download&id=1DxSelmQ9bsO0VJICxC6POteOPuN7qnpE'; // Replace with your PDF link
var pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.js';
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');
// Fetch the first page of the PDF
var pageNumber = 1;
pdf.getPage(pageNumber).then(function(page) {
console.log('Page loaded');
var scale = 1.5; // Scale factor to adjust PDF size
var viewport = page.getViewport({ scale: scale });
// Set up canvas to render the PDF page
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render the PDF page
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext).then(function() {
console.log('Page rendered');
});
});
}, function(reason) {
console.error(reason);
});
</script>
</body>
</html>