---
name: documents
display: 处理 PDF 文档
description: 读 PDF 的文字、按页取、看文档信息,拆分合并后把文件交给用户
aliases: [ "读 PDF", "PDF 转文字", "合并 PDF" ]
terms: [ "PDF", "文档", "提取文字", "按页", "合并", "拆分", "扫描件" ]
title: documents
canonical_url: https://skilld.dev/gh/wangzan101/mika/documents
last_updated: 2026-10-31T03:01:04.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/extract_pdf.py](https://skilld.dev/api/skills-raw/wangzan101/mika/documents/scripts/extract_pdf.py), [scripts/manifest.json](https://skilld.dev/api/skills-raw/wangzan101/mika/documents/scripts/manifest.json).
>
> If the user asked to install this Skill, run `npx skilld install wangzan101/mika/documents`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/documents`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/wangzan101/mika/documents) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/documents`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/documents --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/documents --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

## 入口

先看文档在哪:
- 网上的公开链接:用 `web_navigate` 打开,内置浏览器能直接显示的,读页面就够了。
- 用户发来的附件:在 `/workspace/inbox/`。
- 网页上下载的文件:在 `/workspace/downloads/`,可以用 `web_downloads` 查下载记录。

## 步骤

1. 文字型 PDF 用 `run_bundled_script` 跑 `scripts/extract_pdf.py`,`source` 填 `skills/documents`,文件路径相对 `/workspace` 写:
   - 全文:`args: ["inbox/a.pdf"]`
   - 指定页(从 1 数,可写 `3`、`1-5`、`1,4,7-9`):`args: ["inbox/a.pdf", "--pages", "1-5"]`
   - 标题、作者、页数等信息(JSON):`args: ["inbox/a.pdf", "--metadata"]`
   - 长文档先存成文本:`args: ["inbox/a.pdf", "--out", "a.txt"]`,再用 `read_file` 分段读,或用 `search_files` 找关键词。
   - 有密码的:加 `--password` 和密码。
2. 输出里每页以 `--- page N ---` 开头,引用时按它写页码。
3. 拆分、合并、抽页用 `run_command` 写一小段 Python,调用 pypdf;新文件放在 `/workspace` 下。
4. 做好的文件用 `share_file` 交给用户。

## 容易出错的地方

- 脚本退出码为 3、提示没有可取的文字,说明是扫描出来的图片型 PDF;本机没有文字识别,只能看页面图片或告诉用户这一点。部分页没有文字时,脚本会单独报出这些页。
- 表格、多栏排版取出来的顺序常常是乱的,引用表格里的数字前要对照原页。
- 页码范围超出文档页数时脚本直接报错,先用 `--metadata` 看页数。

## 怎样算办成(核实证据)

给出的文字能在脚本输出里对应到原页,并写了页码;交出去的文件 `share_file` 成功,页数和内容与预期一致(可以对新文件再跑一次 `--metadata` 核对页数)。

## 什么时候停下交给用户

文档有密码而用户没给,或者需要用户决定保留哪些页、按什么顺序合并时,先问用户。
