extract_pdf
Extract text and metadata from a PDF document.
Parameters
- pathstringone of
pathorsource_key - File path to the PDF; supports
${ctx.key}interpolation. - source_keystringone of
pathorsource_key - Context key whose value is the file path (must be a string).
- formatstringdefault "text"
- Output format:
"text"for raw extracted text,"markdown"for best-effort paragraph-grouped Markdown. - output_keystringdefault "content"
- Context key where the extracted text is stored.
- metadata_keystring
- If set, PDF metadata is stored under this context key.
Providing both
pathandsource_keyis an error. Theformatparameter only accepts"text"or"markdown"; any other value is rejected.
Context Output
<output_key>(defaultcontent) — the extracted text or Markdown.<metadata_key>(only whenmetadata_keyis set) — an object with available fields:pages(number),title,author,subject,keywords,creator,producer,created,modified.
Example
local flow = Flow.new("read_pdf")
flow:step("extract", nodes.extract_pdf({
path = "${ctx.file_path}",
format = "text",
output_key = "pdf_text",
metadata_key = "pdf_meta"
}))
flow:step("done", nodes.log({
message = "Pages: ${ctx.pdf_meta.pages}, Content: ${ctx.pdf_text}"
})):depends_on("extract")
return flow