MCPcopy
hub / github.com/mudler/LocalAI / extractTextFromPDF

Function extractTextFromPDF

core/http/static/chat.js:852–869  ·  view source on GitHub ↗
(pdfData)

Source from the content-addressed store, hash-verified

850var audioFileMap = new Map(); // fileName -> dataURL
851
852async 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
872window.handleFileSelection = function(event, fileType) {

Callers 1

readInputFileFileFunction · 0.85

Calls 4

getPageMethod · 0.45
getTextContentMethod · 0.45
mapMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected