(pdfPath: string)
| 33 | type FileMetadata = Record<string, { path: string; type: string; format?: string }>; |
| 34 | |
| 35 | export 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 | |
| 54 | export function resolveVariables( |
| 55 | variables: Record<string, VarValue>, |
no outgoing calls
no test coverage detected
searching dependent graphs…