MCPcopy
hub / github.com/promptfoo/promptfoo / extractTextFromPDF

Function extractTextFromPDF

src/evaluatorHelpers.ts:35–52  ·  view source on GitHub ↗
(pdfPath: string)

Source from the content-addressed store, hash-verified

33type FileMetadata = Record<string, { path: string; type: string; format?: string }>;
34
35export async function extractTextFromPDF(pdfPath: string): Promise<string> {
36 logger.debug(`Extracting text from PDF: ${pdfPath}`);
37 try {
38 const { PDFParse } = await import('pdf-parse');
39 const dataBuffer = await fs.readFile(pdfPath);
40 const parser = new PDFParse({ data: dataBuffer });
41 const result = await parser.getText();
42 await parser.destroy();
43 return result.text.trim();
44 } catch (error) {
45 if (error instanceof Error && error.message.includes("Cannot find module 'pdf-parse'")) {
46 throw new Error('pdf-parse is not installed. Please install it with: npm install pdf-parse');
47 }
48 throw new Error(
49 `Failed to extract text from PDF ${pdfPath}: ${error instanceof Error ? error.message : String(error)}`,
50 );
51 }
52}
53
54export function resolveVariables(
55 variables: Record<string, VarValue>,

Callers 2

renderPromptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…