Marthee commited on
Commit
20eef6f
·
verified ·
1 Parent(s): 4d974bc

Update templates/gui.html

Browse files
Files changed (1) hide show
  1. templates/gui.html +24 -16
templates/gui.html CHANGED
@@ -5,7 +5,9 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>View PDF with PDF.js</title>
7
 
 
8
  <script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
 
9
  <style>
10
  canvas {
11
  width: 100%;
@@ -17,31 +19,37 @@
17
 
18
  <h2>PDF Viewer</h2>
19
 
 
20
  <div id="pdf-container"></div>
21
 
22
  <script>
23
  async function renderPdf() {
24
- const url = '/download-pdf';
25
- const loadingTask = pdfjsLib.getDocument(url);
 
 
 
 
26
 
27
- const pdf = await loadingTask.promise;
28
- const page = await pdf.getPage(2);
29
 
30
- const scale = 1.5;
31
- const viewport = page.getViewport({ scale });
 
 
32
 
33
- const canvas = document.createElement('canvas');
34
- const context = canvas.getContext('2d');
35
- canvas.height = viewport.height;
36
- canvas.width = viewport.width;
37
 
38
- const renderContext = {
39
- canvasContext: context,
40
- viewport: viewport
41
- };
42
 
43
- page.render(renderContext);
44
- document.getElementById('pdf-container').appendChild(canvas);
 
45
  }
46
 
47
  renderPdf();
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>View PDF with PDF.js</title>
7
 
8
+ <!-- Include PDF.js -->
9
  <script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
10
+
11
  <style>
12
  canvas {
13
  width: 100%;
 
19
 
20
  <h2>PDF Viewer</h2>
21
 
22
+ <!-- Container where PDF content will be rendered -->
23
  <div id="pdf-container"></div>
24
 
25
  <script>
26
  async function renderPdf() {
27
+ try {
28
+ const url = '/download-pdf';
29
+ const loadingTask = pdfjsLib.getDocument(url);
30
+
31
+ const pdf = await loadingTask.promise;
32
+ const page = await pdf.getPage(2);
33
 
34
+ const scale = 1.5;
35
+ const viewport = page.getViewport({ scale });
36
 
37
+ const canvas = document.createElement('canvas');
38
+ const context = canvas.getContext('2d');
39
+ canvas.height = viewport.height;
40
+ canvas.width = viewport.width;
41
 
42
+ const renderContext = {
43
+ canvasContext: context,
44
+ viewport: viewport
45
+ };
46
 
47
+ page.render(renderContext);
48
+ document.getElementById('pdf-container').appendChild(canvas);
 
 
49
 
50
+ } catch (error) {
51
+ console.error('Failed to load PDF:', error);
52
+ }
53
  }
54
 
55
  renderPdf();