MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / read_pdf

Function read_pdf

src/modules/loadFiles.ts:9–35  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

7const pdfjsLib = pdfjsLibRaw as typeof pdfjsLibModule;
8
9async function read_pdf(file: File) {
10 const typedArray = await file.arrayBuffer();
11
12 // Load the PDF file.
13 //const loadingTask = PDFJS.getDocument(pdfData);
14 //const pdf = await pdfjsLib.getDocument({ data: typedArray }).promise;
15 //const pdf = await pdfjsLib.getDocument({ data: typedArray }).promise;
16 const loadingTask = pdfjsLib.getDocument({ data: typedArray });
17 const pdf = await loadingTask.promise;
18
19 let textContent = '';
20
21 for (let i = 1; i <= pdf.numPages; i++) {
22 // Fetch the page
23 const page = await pdf.getPage(i);
24
25 // Fetch the text content
26 const text = await page.getTextContent();
27
28 // Concatenate the text
29 textContent += text.items
30 .map((item) => ('str' in item ? item.str : ''))
31 .join('\n');
32 }
33
34 return textContent;
35}
36
37async function read_docx(file: File) {
38 const arrayBuffer = await file.arrayBuffer();

Callers 1

loadFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected