(pdfData)
| 850 | var audioFileMap = new Map(); // fileName -> dataURL |
| 851 | |
| 852 | async function extractTextFromPDF(pdfData) { |
| 853 | try { |
| 854 | const pdf = await pdfjsLib.getDocument({ data: pdfData }).promise; |
| 855 | let fullText = ''; |
| 856 | |
| 857 | for (let i = 1; i <= pdf.numPages; i++) { |
| 858 | const page = await pdf.getPage(i); |
| 859 | const textContent = await page.getTextContent(); |
| 860 | const pageText = textContent.items.map(item => item.str).join(' '); |
| 861 | fullText += pageText + '\n'; |
| 862 | } |
| 863 | |
| 864 | return fullText; |
| 865 | } catch (error) { |
| 866 | console.error('Error extracting text from PDF:', error); |
| 867 | throw error; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | // Global function to handle file selection and update Alpine.js state |
| 872 | window.handleFileSelection = function(event, fileType) { |
no test coverage detected