pdf-book-chapter-site
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "pdf-book-chapter-site" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-c0a5616c916c8e7bbc16929a377c5b63d45c7aa804af36fca04870221d00d508. Verify the upstream source and version against https://skillhub.cn/skills/user_126b7108/pdf1 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Breaks a PDF book into a chaptered, independently accessible HTML site. Produces a table of contents, per-chapter pages, intra-chapter navigation and previous/next links, and deploys to CloudStudio for an online access URL. Intended for requests to split a book into chapters or generate an online TOC, especially for Chinese investment/finance PDFs with word-by-word line breaks.
Introduction source: third_party · user_126b7108 · 1.1 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Inputs and outputs
- Translation pending; see source documentation.
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: pdf-book-chapter-site
description: 将一本 PDF 书籍(尤其中文投资/金融类,文本常被逐字拆行)拆解为"章节化、可独立在线访问的 HTML 站点"——含目录页 + 每章独立页面 + 章节内导航 + 上一页/下一页,并部署到 CloudStudio 获得在线地址。当用户说"拆解这本书/把PDF分成章节/生成可在线访问的章节页面/做个目录页"时使用。
type: workflow
version: 1.1PDF 书籍 → 章节化自包含 HTML 站点
何时使用
- 用户提供一本 PDF 书,要求"拆解总结 / 分成章节 / 每章一个独立 HTML 页面 / 能在线访问 / 做个目录页"。
- 适合中文书(金融投资类常见),尤其是张志雄《Value》版等"目录重排、正文用原版章节编号"的译本。
核心难点(必读)
- 文本逐字拆行:很多中文 PDF 的文本层把每个汉字单独放一行,或把"第 二 章"跨行拆分,导致整行正则匹配章节标题失效。
- 用
pdfplumber提取(比 pypdf 干净),并跨行拼接来检测标题。
- 用
- 扫描版/图片型 PDF 无文字层:
pdfplumber.extract_text()返回空或极短。需要先渲染页面为图片,再做 OCR。- 用
PyMuPDF(fitz)把每页渲染成 PNG:page.get_pixmap(matrix=fitz.Matrix(dpi/72, dpi/72))。 - 用
rapidocr_onnxruntime做中文 OCR(pip install rapidocr_onnxruntime),比 tesseract 更轻量、纯 pip 安装,准确率对印刷体足够。 - 多进程并行:
Pool(..., initializer=init_rapidocr),worker 数取min(8, cpu_count())。 - OCR 后得到
p0001.txt ~ pXXXX.txt,再按目录页码或正则切分章节。
- 用
- 目录结构 vs 正文结构不一致:译本目录常把原版多章重排为"3 大章 + N 小节",而正文仍用原版"第X章"编号。以用户可见的目录 + 正文页码边界共同确定切分。
工作流(5 步)
1. 提取与切分
import pdfplumber, os
PDF="book.pdf"; OUT="extracted"; os.makedirs(OUT, exist_ok=True)
with pdfplumber.open(PDF) as pdf:
pages=[p.extract_text() or "" for p in pdf.pages]
# 先探测边界:用跨行容错的正则找"第X章/第X部分/附录X/编后记"
import re
pat=re.compile(r'^(第[一二三四五六七八九十]+\s*[部分章])\s*([\u4e00-\u9fff].{0,25})?')
for i,p in enumerate(pages):
for ln in p.splitlines():
if pat.match(ln.strip()): print(i+1, ln.strip()[:45])
# 按确定的页码范围写入 part1/part2/.../intro/app1... 文本文件
- 边界确定后,用
pages[a-1:b]切片保存各章文本,便于子代理/人工阅读。
2. 并行总结(省上下文)
- 把三大块(或每章)文本文件分给 多个并行 general-purpose 子代理(run_in_background=true),各自读文件、产出结构化中文 markdown 总结(模板:章节概述 / 各小节:核心论点、关键概念、案例与例证、重要引述、本节要点 / 本章核心金句),写入
summary_xxx.md。 - 导言与附录可由主代理亲自读原文撰写(篇幅小)。
3. 生成自包含 HTML 站点
- 每个页面内联 CSS/JS(无外部依赖),这样无论本地打开还是托管都能"独立访问"。
- 必备组件:
- 顶部 sticky 栏 + 目录抽屉(off-canvas,列出全部章节与子节,当前页高亮)。
- 正文用轻量 markdown→HTML 转换器(处理
#/##/###、-列表、1./1、有序列表、>引用、**粗体**、<hr>)。 - 右侧 sticky 章节内导航(用
##标题做锚点,IntersectionObserver 高亮当前节)。 - 底部 上一页/下一页 翻页条。
- 顶部阅读进度条 + 回到顶部按钮。
- 锚点 slugify:中文标题做 id 时剔除
、,。:()等标点(替换为-),且抽屉/章节内导航的#锚点必须与正文id用同一 slugify,否则点击不跳转。 - 生成
index.html:书籍封面 hero + 全书结构卡片(每章可展开子节,点击跳转到chapterX.html#锚点)。
4. 本地验证
cd site && python -m http.server 8765 &
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8765/index.html # 应 200
# 校验锚点:每个页面 href="#x" 都能找到对应 id=
- 检查无残留
__CSS__/__JS__/__TITLE__等占位符。
5. 部署到 CloudStudio(满足"独立在线访问")
- 用
workbuddy_cloudstudio_deploy(directory=site, entry=index.html, port=3000)。 - 返回 shareLink;每个页面在线地址为
shareLink/chapterX.html(curl 验证 200)。
输出清单(典型)
index.html + intro.html + chapter1~3.html + appendix1~3.html + afterword.html(共 9 页),相对链接互相跳转,整站可整体托管。
注意
- 总结必须忠实原文,引用尽量用书中原话(中文),不虚构。
- 金融书常含敏感/合规内容,仅做学习向拆解总结,注明"仅供学习交流"。
Current listing version
1.1
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决中文 PDF 文本逐字拆行、OCR 处理、目录与正文结构不一致等实际痛点
- 提供端到端闭环:从 PDF 提取到部署可在线访问的章节化站点
- 适用于高频文档处理场景,实用价值高
Highlights
- 触发词覆盖全面(拆解/分成章节/在线访问/目录页等),边界清晰
- description 明确指向用户典型表达方式
Areas to improve
-
description写错位置 Reported severity: Minor
顶层 frontmatter 与 skill_body 内部均含 description,存在冗余
Recommendation: 建议仅保留顶层 frontmatter 中的 description,移除 skill_body 内重复内容
-
文档过长 Reported severity: Minor
skill_body 内容约 600 行,超出建议单文件长度
Recommendation: 可考虑将核心难点或工作流细节移至独立文档并通过引用链接
Highlights
- 工作流分 5 步清晰明确,含代码示例与验证逻辑
- frontmatter 完整,包含 name、description、type、version
Highlights
- 工具链明确(pdfplumber + PyMuPDF + rapidocr_onnxruntime),参数合理
- 覆盖文本提取失败、OCR 处理、多进程并行等关键异常场景
- 本地验证与 CloudStudio 部署步骤完整,确保端到端可执行
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 19
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- localhost
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.