pdf-parsinglisted
Install: claude install-skill black-yt/skills
# PDF 解析
## 目标
把 PDF 文档解析成本地可读取、可搜索、可复制的 Markdown,并抽取 PDF 中的图片资源。解析完成后,后续阅读应优先使用本地 Markdown 文件;重复调用 `structai.read_pdf` 也会优先复用本地解析结果,不会在本地结果已存在时重复上传同一个 PDF。
## 依赖安装
```bash
pip install structai
```
如果包索引中找不到 `structai`,或需要使用 GitHub 仓库中的最新代码:
```bash
pip install "git+https://github.com/black-yt/structai.git"
```
校验:
```bash
python3 -c "from structai import read_pdf; import inspect; print(inspect.signature(read_pdf))"
```
如果当前环境同时有多个 Python,请确认 `pip` 和 `python3` 指向同一个环境:
```bash
python3 -m pip show structai
python3 -c "import structai; print(structai.__file__)"
```
## `read_pdf` 源码追溯
- `read_pdf` 行为以当前安装版本源码为准;如果缓存、上传、下载、图片路径或返回值和预期不一致,先读源码再判断。
- `inspect.signature(read_pdf)` 用于看函数参数。
- `inspect.getsource(read_pdf)` 用于看 `read_pdf` 入口逻辑。
- `structai.__file__` 和 `structai.pdf.__file__` 用于定位安装包源码文件。
- 源码只用于阅读和定位问题,不要改源码,不要直接修改 `site-packages` 或共享环境;需要改库时,先 clone `https://github.com/black-yt/structai`,在用户确认后用 editable install。
```bash
python3 - <<'PY'
import inspect
import structai
import structai.pdf as pdf_mod
from structai import read_pdf
print("structai:", structai.__file__)
print("structai.pdf:", pdf_mod.__file__)
print("signature:", inspect.signature(read_pdf))
print(inspect.getsource(read_pdf))
PY
```
如果要继续追 `read_pdf` 调用的内部函数,先查看 `structai.pdf` 模块源码路径,再按函数名读取:
```bash
python3 - <<'PY'
import inspect
import structai.pdf as pdf_mod
print(pdf_mod.__file__)
for name in ["get_headers"]:
obj = getattr(pdf_mod, name, None)
if obj is not None:
print