Book PDF to Structured JSON
把整本 PDF 重建为可审计、可上传验证的 JSON/TXT 电子版
yaxin LIU
@yasmineliu
Install
$ openclaw skills install @yasmineliu/book-pdf-to-structured-jsonBook PDF to Structured JSON
Produce a traceable electronic edition whose hierarchy comes from the printed table of contents and whose remote copy can be proven identical to the reviewed local JSON.
Read the right reference
- Read references/pipeline.md before planning or executing a book conversion.
- Use scripts/compare_tree_export.py after a full remote export. It compares titles, bodies, levels, order, and parent relationships and emits reproducible SHA-256 fingerprints.
Core rules
- Treat the rendered printed TOC as the structural authority. Do not infer the final tree only from OCR body headings.
- Preserve source evidence: page boundaries, source-page mapping, heading-match score, and the original extracted text.
- Separate detection from correction. OCR models and rare-character audits propose candidates; only reviewed, context-safe rules may change text.
- Make the JSON tree the authoritative deliverable. Generate TXT, TSV, chapter files, and upload payloads from that same tree.
- Fail closed on uncertain headings, missing parents, duplicate keys, cycles, unexpected node counts, empty leaf content, or unexplained text loss.
- Never mutate a remote environment until the user has authorized upload and the exact environment, equipment/library ID, and book set are known.
- Export a full remote backup before replacement. Pass credentials through environment variables or standard input; never place tokens in commands, reports, or logs.
- After upload, export full remote bodies and compare normalized content and structure. Counts alone are not acceptance evidence.
Access and authorization
- Read only the source books and extraction evidence the user placed in scope.
- Write only to the approved local output and audit locations.
- Use network access only when the user explicitly requests upload or remote read-back verification.
- Do not create background jobs, persistence, credential stores, or privilege changes.
Execution outline
- Inventory sources and classify each as text PDF, scanned PDF, DOCX, or TXT.
- Extract page-aware UTF-8 text; use OCR only where the text layer is absent or demonstrably worse.
- Render and transcribe the printed TOC, including hierarchy, printed page number, and expected item count.
- Locate every TOC heading near its expected source page; record score and offsets, and stop for ambiguous matches.
- Slice content between adjacent located headings and clean only layout artifacts and reviewed OCR errors.
- Build and validate the canonical tree, then generate all derivative artifacts.
- Run static, structural, semantic-candidate, and cross-artifact audits. Review candidate corrections and rerun validation.
- If upload is requested, back up the target, import only the authorized books, read back the full dataset, and run the deterministic comparator.
- Report the exact local version directory, book/node totals, audit results, backup path, remote target, and per-book fingerprints.
Completion standard
Do not call the work complete unless:
- every printed TOC entry maps to exactly one node in the intended order;
- every parent exists and the hierarchy is acyclic and level-consistent;
- expected content-bearing nodes are nonempty;
- no unexplained replacement characters, mojibake, private-use glyphs, page headers, or page markers remain;
- running headers are removed even when the PDF text layer merges them into an adjacent body line, and footnotes do not interrupt or reorder a sentence continued on the next page;
- the final included node ends at a reviewed terminal boundary rather than blindly consuming the PDF tail;
- JSON parses and all derivative files are regenerated from it;
- the remote full export matches the reviewed local tree when an upload occurred.
Top skills in this category
Nano Pdf
@steipeteEdit PDFs with natural-language instructions using the nano-pdf CLI.
Word / DOCX
@ivangdavilaCreate, inspect, and edit Microsoft Word documents and DOCX files with reliable styles, numbering, tracked changes, tables, sections, and compatibility check...
Excel / XLSX
@ivangdavilaCreate, inspect, and edit Microsoft Excel workbooks and XLSX files with reliable formulas, dates, types, formatting, recalculation, and template preservation...
Markdown Converter
@steipeteConvert documents and files to Markdown using markitdown. Use when converting PDF, Word (.docx), PowerPoint (.pptx), Excel (.xlsx, .xls), HTML, CSV, JSON, XML, images (with EXIF/OCR), audio (with transcription), ZIP archives, YouTube URLs, or EPubs to Markdown format for LLM processing or text analysis.
Powerpoint / PPTX
@ivangdavilaCreate, inspect, and edit Microsoft PowerPoint presentations and PPTX decks with reliable layouts, templates, placeholders, notes, charts, and visual QA. Use...