Extract Content With Image
Documentsextract_content_with_imageExtract Content With Image is an Agent Skill for documents published in the landingbj/LinkMind repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
将本地 PDF、TXT、Word、PPT 文件分割为文本和图片chunk。
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/landingbj/LinkMind/blob/HEAD/lagi-web/src/main/resources/skills/extract_content_with_image/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/extract-content-with-image, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
extract_content_with_image
使用方式
执行脚本前请先激活环境
- 脚本入口:
scripts/extract_content_with_image.py - 参数:
argv[1]为待处理文件的本地绝对路径 - 支持输入:
.pdf、.txt、.doc、.docx、.ppt、.pptx
输出格式(stdout)
- 仅输出一个 JSON 对象,便于 Java 侧直接
json.loads/parseJsonObject - 成功:
{"status":"success","filepath":"...pdf","data":[...]} - 失败:
{"status":"failed","msg":"<具体异常信息>"} data中每个元素形如:{"text":"...", "image":"<图片列表的 JSON 字符串或空串>"}
运行依赖
- 必需:
PyMuPDF(fitz)和Pillow - 可选:
soffice,用于.doc/.docx/.ppt/.pptx/.txt转 PDF;可用环境变量SOFFICE_PATH指定 - 无
soffice时:.txt会直接用fitz生成 PDF,并基于原始文本做分块.doc/.docx/.ppt/.pptx会返回失败 JSON
- 可选:
transformers+TOKENIZER_DIR或MODEL_DIR- 配置后按 tokenizer 的 token 数分块,和 VicunaIndex 更接近
- 未配置时按字符数分块,默认
CHUNK_SIZE=512
行为说明
- 脚本会先把输入文件复制到
SKILL_OUTPUT_DIR/extract_content_with_image/<run_id>/files/ - 若发生格式转换,
filepath返回转换后的 PDF 路径 - 图片会裁剪到同一个运行目录下,并在
image字段中以绝对路径返回 page_dir会在结束时清理,保留裁剪后的图片文件