Spaces:
Sleeping
Sleeping
Update templates/gui.html
Browse files- templates/gui.html +42 -44
templates/gui.html
CHANGED
|
@@ -3,60 +3,58 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>View PDF
|
| 7 |
-
|
| 8 |
-
<!-- Include PDF.js -->
|
| 9 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.938/pdf.min.js"></script>
|
| 10 |
-
|
| 11 |
<style>
|
| 12 |
-
|
| 13 |
width: 100%;
|
| 14 |
-
height:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
</style>
|
| 17 |
-
</head>
|
| 18 |
-
<body>
|
| 19 |
-
|
| 20 |
-
<h2>PDF Viewer</h2>
|
| 21 |
|
| 22 |
-
<!--
|
| 23 |
-
<
|
| 24 |
|
| 25 |
<script>
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
// Load the PDF using PDF.js
|
| 31 |
-
const loadingTask = pdfjsLib.getDocument(url);
|
| 32 |
-
|
| 33 |
-
const pdf = await loadingTask.promise;
|
| 34 |
-
const page = await pdf.getPage(2);
|
| 35 |
-
|
| 36 |
-
const scale = 1.5;
|
| 37 |
-
const viewport = page.getViewport({ scale });
|
| 38 |
-
|
| 39 |
-
const canvas = document.createElement('canvas');
|
| 40 |
-
const context = canvas.getContext('2d');
|
| 41 |
-
canvas.height = viewport.height;
|
| 42 |
-
canvas.width = viewport.width;
|
| 43 |
-
|
| 44 |
-
const renderContext = {
|
| 45 |
-
canvasContext: context,
|
| 46 |
-
viewport: viewport
|
| 47 |
-
};
|
| 48 |
-
|
| 49 |
-
page.render(renderContext);
|
| 50 |
-
document.getElementById('pdf-container').appendChild(canvas);
|
| 51 |
-
|
| 52 |
-
} catch (error) {
|
| 53 |
-
console.error('Failed to load PDF:', error);
|
| 54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
-
|
| 57 |
-
renderPdf
|
| 58 |
</script>
|
|
|
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</body>
|
| 61 |
</html>
|
| 62 |
-
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>View PDF</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
+
iframe {
|
| 9 |
width: 100%;
|
| 10 |
+
height: 100vh;
|
| 11 |
+
border: none;
|
| 12 |
+
}
|
| 13 |
+
.pdf-container {
|
| 14 |
+
text-align: center;
|
| 15 |
}
|
| 16 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
<!-- Include PDF.js -->
|
| 19 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.938/pdf.min.js"></script>
|
| 20 |
|
| 21 |
<script>
|
| 22 |
+
function renderPdf() {
|
| 23 |
+
if (typeof pdfjsLib === 'undefined') {
|
| 24 |
+
console.error('PDF.js is not loaded.');
|
| 25 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
+
|
| 28 |
+
const url = '/download-pdf'; // Flask route to serve the PDF
|
| 29 |
+
|
| 30 |
+
pdfjsLib.getDocument(url).promise.then(function(pdf) {
|
| 31 |
+
console.log('PDF loaded');
|
| 32 |
+
pdf.getPage(2).then(function(page) {
|
| 33 |
+
const viewport = page.getViewport({ scale: 1.5 });
|
| 34 |
+
const canvas = document.getElementById('pdfCanvas');
|
| 35 |
+
const context = canvas.getContext('2d');
|
| 36 |
+
|
| 37 |
+
canvas.height = viewport.height;
|
| 38 |
+
canvas.width = viewport.width;
|
| 39 |
+
|
| 40 |
+
page.render({
|
| 41 |
+
canvasContext: context,
|
| 42 |
+
viewport: viewport
|
| 43 |
+
});
|
| 44 |
+
});
|
| 45 |
+
}).catch(function(error) {
|
| 46 |
+
console.error('Failed to load PDF:', error);
|
| 47 |
+
});
|
| 48 |
}
|
| 49 |
+
|
| 50 |
+
window.onload = renderPdf;
|
| 51 |
</script>
|
| 52 |
+
</head>
|
| 53 |
|
| 54 |
+
<body>
|
| 55 |
+
<h2>PDF Viewer</h2>
|
| 56 |
+
<div class="pdf-container">
|
| 57 |
+
<canvas id="pdfCanvas"></canvas>
|
| 58 |
+
</div>
|
| 59 |
</body>
|
| 60 |
</html>
|
|
|