-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtranscript-gpt.html
More file actions
52 lines (47 loc) · 2.14 KB
/
transcript-gpt.html
File metadata and controls
52 lines (47 loc) · 2.14 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF to Text</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
</head>
<body>
<h1>Upload PDF to Extract Text</h1>
<input type="file" id="pdf-file" accept="application/pdf">
<pre id="output"></pre>
<script>
document.getElementById('pdf-file').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file && file.type === 'application/pdf') {
const reader = new FileReader();
reader.onload = function(e) {
const pdfData = new Uint8Array(e.target.result);
// Using PDF.js to read the PDF
pdfjsLib.getDocument(pdfData).promise.then(function(pdf) {
let textContent = '';
const numPages = pdf.numPages;
let pagePromises = [];
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
pagePromises.push(pdf.getPage(pageNum).then(function(page) {
return page.getTextContent().then(function(text) {
textContent += text.items.map(item => item.str).join(" XXX ") + " New page \n";
});
}));
}
// After all pages are processed, output the text
Promise.all(pagePromises).then(function() {
document.getElementById('output').textContent = textContent;
});
}).catch(function(error) {
document.getElementById('output').textContent = 'Error reading PDF: ' + error;
});
};
reader.readAsArrayBuffer(file);
} else {
alert('Please upload a valid PDF file.');
}
});
</script>
</body>
</html>