-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (67 loc) · 3.05 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Highlight PDF Text</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container mt-5">
<form id="highlightForm" enctype="multipart/form-data" class="mt-4">
<div class="form-group">
<label for="fileurl">Fileurl:</label>
<input type="text" id="fileurl" name="fileurl" class="form-control">
</div>
OR
<div class="form-group mt-2">
<label for="file">File:</label>
<input type="file" id="file" name="file" class="form-control-file" accept=".pdf">
</div>
<div class="mt-2 form-group">
<label for="page_number">Page Number:</label>
<input type="number" id="page_number" name="page_number" class="form-control" required>
</div>
<div class="mt-2 form-group">
<label for="text">Text:</label>
<textarea id="text" name="text" class="form-control" rows="3" required></textarea>
</div>
<button type="submit" class="mt-2 btn btn-primary">Highlight Text</button>
</form>
</div>
<div id="output">
<!-- Output image will be displayed here -->
</div>
<script>
document.getElementById('highlightForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the default form submission
// Create FormData object
var formData = new FormData(this);
// Make a POST request to the Flask route
fetch('http://localhost:5000/highlight', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.error) {
console.error(data.error);
} else {
// Create an image element to display the highlighted image
var img = document.createElement('img');
img.src = 'data:image/png;base64,' + data.image_data_base64;
img.alt = 'Highlighted PDF Text';
// Clear previous output
document.getElementById('output').innerHTML = '';
// Append the image to the output div
document.getElementById('output').appendChild(img);
}
})
.catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</html>