Marthee commited on
Commit
a0786f3
·
verified ·
1 Parent(s): fbde37a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -60
app.py CHANGED
@@ -1,60 +1,63 @@
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>
 
 
 
 
1
+ from flask import Flask, send_file, render_template
2
+ import requests
3
+ from io import BytesIO
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ app = Flask(__name__)
19
+
20
+
21
+ @app.route("/", methods=["GET", "POST"])
22
+ def get_inf_to_measure():
23
+ """
24
+ Render the main GUI with the iframe.
25
+ """
26
+ return render_template("gui.html")
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ # Route to serve the PDF in iframe
38
+ @app.route('/download-pdf', methods=['GET'])
39
+ def serve_pdf():
40
+ 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'
41
+ if 'dl=0' in link:
42
+ link = link.replace('dl=0', 'dl=1')
43
+ response = requests.get(link)
44
+ pdf_content = BytesIO(response.content)
45
+ return send_file(pdf_content, download_name="document.pdf", mimetype="application/pdf")
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ if __name__ == '__main__':
62
+ # Run the application with a specified host and port
63
+ app.run(host='0.0.0.0', port=7860)