Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,60 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def serve_pdf():
|
| 17 |
-
link = 'https://www.dropbox.com/scl/fi/fjykwhhn9gu9t3kqrflxd/LA002-NOR-ZZ-ZZ-T-A-2403_Architectural-Specification-F10-Brick-and-Block-Walling_A4-_C01.pdf?rlkey=ek9i66i79m0hwp8z5yjs6rp5p&st=jh05a6qs&dl=0'
|
| 18 |
-
if 'dl=0' in link:
|
| 19 |
-
link = link.replace('dl=0', 'dl=1')
|
| 20 |
-
response = requests.get(link)
|
| 21 |
-
pdf_content = BytesIO(response.content)
|
| 22 |
-
return send_file(pdf_content, download_name="document.pdf", mimetype="application/pdf")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 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>
|