{"record":{"id":"129e283555711f85","repo":"n8n-io/n8n","slug":"failed-to-parse-pdf-attachment-filename-me","errorCode":null,"errorMessage":"Failed to parse PDF \"${attachment.fileName}\": ${message}","messagePattern":"Failed to parse PDF \"(.+?)\": (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/src/parsers/pdf-parser.ts","lineNumber":43,"sourceCode":"\t// pdf-parse v2 is backed by pdfjs-dist, which expects a `DOMMatrix` global\n\t// that Node.js does not provide. Polyfill it before parsing.\n\tif (typeof Reflect.get(globalThis, 'DOMMatrix') === 'undefined') {\n\t\tconst { default: DOMMatrix } = await import('@thednp/dommatrix');\n\t\tReflect.set(globalThis, 'DOMMatrix', DOMMatrix);\n\t}\n\n\tconst { PDFParse } = await import('pdf-parse');\n\n\tconst parser = new PDFParse({ data: decoded });\n\tlet extractedText: string;\n\tlet totalPages: number;\n\ttry {\n\t\tconst result = await parser.getText();\n\t\textractedText = result.text;\n\t\ttotalPages = result.total;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : 'unknown error';\n\t\tthrow new Error(`Failed to parse PDF \"${attachment.fileName}\": ${message}`);\n\t} finally {\n\t\tawait parser.destroy();\n\t}\n\n\tconst text = extractedText?.trim() ?? '';\n\tif (!text) {\n\t\tthrow new Error(\n\t\t\t`PDF \"${attachment.fileName}\" contains no extractable text (it may be a scanned image).`,\n\t\t);\n\t}\n\n\tif (text.length > MAX_RESULT_CHARS) {\n\t\treturn {\n\t\t\ttext: text.slice(0, MAX_RESULT_CHARS),\n\t\t\tpages: totalPages,\n\t\t\ttruncated: true,\n\t\t};\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/src/parsers/pdf-parser.ts#L25-L61","documentation":"Error \"Failed to parse PDF \"${attachment.fileName}\": ${message}\" thrown in n8n-io/n8n.","triggerScenarios":"Thrown at packages/@n8n/instance-ai/src/parsers/pdf-parser.ts:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}