File size: 3,573 Bytes
e05934a
39301a8
 
 
 
 
 
 
1b6544e
39301a8
 
 
 
 
 
 
a8c6dd8
 
 
 
 
 
 
 
 
06369f2
3aa61c1
a8c6dd8
 
 
39301a8
 
a8c6dd8
 
6aef526
39301a8
84a2268
39301a8
 
 
 
 
 
a8c6dd8
39301a8
 
 
 
 
 
 
 
 
 
 
a8c6dd8
 
 
e05934a
 
 
 
 
 
 
 
bce0410
 
e05934a
 
 
 
bce0410
 
 
 
e05934a
 
bce0410
 
 
 
 
e05934a
bce0410
 
 
 
 
 
 
 
 
e05934a
bce0410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e05934a
 
bce0410
e05934a
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!-- <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF NBS Search - ADR MVP.1</title>
</head>
<body>
  hi
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.min.js"></script>
<script > 

///////////////////////////////////////////////BEGIN JS CODE//////////////////////////////////////////////////
// Function to send the Dropbox link and keyword to the server
function getURLParams() {
    const urlParams = new URLSearchParams(window.location.search);
    return {
        pdfLink: urlParams.get('pdfLink'),
        keyword: JSON.parse(decodeURIComponent(urlParams.get('keyword') || "[]")),  // Decode and parse
        pageNumber: parseInt(urlParams.get('page')) || 1,
        zoomRect: urlParams.get('zoom')  // Expecting format: "x,y,width,height"
    };
}

function processPdf() {
    // const pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'; // Dropbox link
    // const keyword = ['115 INTEGRATED MRI ROOM LININGS','710 TRANSPORTATION'] ;  // Example keyword
    const { pdfLink, keyword, pageNumber, zoomRect } = getURLParams();
    // Create a new FormData object to send the data as form data
    const formData = new FormData();
    formData.append('pdf_link', pdfLink);
    formData.append('keyword', JSON.stringify(keyword)); 
    console.log('ay haga pleaseee')
    // Send the data to the Flask server
    fetch('/apiNBSData', {
        method: 'POST',
        body: formData,
    })
    .then(response => response.json())
    .then(data => {
        if (data.download_link) {
            window.location.href = data.download_link; // This will use the rect info from Flask
        } else {
            alert('Error: ' + data.error);
        }
    })
    .catch(error => {
        console.error('Error:', error);
    });
}

// Call the function to process the PDF
processPdf();



</script> -->

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>PDF Viewer</title>
  <style>
    body { margin: 0; overflow: hidden; }
    iframe { width: 100vw; height: 100vh; border: none; }
  </style>
</head>
<body>

  <!-- PDF viewer -->
  <iframe id="pdfViewer"
          src="/get-pdf#page={{ start_page }}&zoom={{ start_zoom }}"
          allowfullscreen></iframe>

  <script>
    /**
     * Listen for external navigation updates.
     * If the viewer is already open, update the page/zoom dynamically
     * when the user clicks another external /view-pdf?pdfLink=...&page=X&zoom=Y link.
     */

    // Detect changes to URL parameters dynamically
    function getQueryParams() {
      const params = new URLSearchParams(window.location.search);
      return {
        pdfLink: params.get('pdfLink'),
        page: params.get('page') || '1',
        zoom: params.get('zoom') || '100'
      };
    }

    function updatePDFView(page, zoom) {
      const iframe = document.getElementById('pdfViewer');
      iframe.src = `/get-pdf#page=${page}&zoom=${zoom}`;
    }

    // Listen for URL changes (e.g. when user clicks another link externally)
    window.addEventListener('popstate', () => {
      const { page, zoom } = getQueryParams();
      updatePDFView(page, zoom);
    });

    // Also handle initial load (page refresh or direct open)
    window.addEventListener('load', () => {
      const { page, zoom } = getQueryParams();
      updatePDFView(page, zoom);
    });
  </script>

</body>
</html>