Home / All Skills / Docs & Knowledge / pdf-to-html
Docs & Knowledge · daymade/claude-code-skills

pdf-to-html

Converts a PDF into one self-contained, readable HTML file that preserves images, tables, charts and reading order — optionally translating it into another language while keeping every figure. Uses structured extraction (PyMuPDF), font-size-driven layout, compressed base64-inlined images (a single portable file), and mandatory headless-Chrome visual verification. Use whenever someone wants to READ a PDF as a web page or clean document, turn a PDF into HTML, or translate a PDF into another language while keeping its images/tables/charts intact — e.g. "PDF 转 HTML", "把这个 PDF 转成中文网页版", "make this report readable", "translate this PDF but don't lose the charts", "I just want to read this PDF on my phone". Distinct from doc-to-markdown (plain Markdown text) and pdf-creator (Markdown→PDF) — this one produces a styled, image-faithful HTML reading experience.

L4 High-Privilege · Graded auth & full auditV1 Commit-PinnedExecute CommandData ExfiltrationNetwork AccessWrite FileDual-pass Audit
Author daymadeGitHub daymade/claude-code-skills ↗Stars 1385License MIT(仓库根 LICENSE;Copyright (c) 2025 daymade;GitHub API spdx MIT)Commit d5c4678cb5
Control levels describe skill capabilities and suggested control measures; they do not represent quality or safety certifications, nor do they dictate usability. Usage decisions rest entirely with users and administrators. Different agent hosts apply varying constraints; do not assume hosts provide automatic protection. Third-party skill copyrights belong to their original authors. Use at your own risk.

1How It Works & Mechanism

The pipeline is extract → look → (translate) → build → verify, where intermediate 'inspecting' and final 'verifying' are defined as the true foundation of fidelity—since a PDF is a layout, not a plain text stream.

daymade-docs/pdf-to-html/SKILL.md
The pipeline is **extract → look → (translate) → build → verify**. The middle "look" and final "verify" steps are where faithfulness actually comes from: a PDF is a layout, not just a text stream, so you read the rendered pages before building and the rendered HTML before delivering.
The workflow section turns it into an actionable checklist (1. Extract, 2. Inspect rendered page PNGs, 3. Optional translation, 4. Build, 5. Visual verification, 6. Deliver).

extract_pdf.py produces reviewable intermediate artifacts: structure.json (per-page text blocks with bbox + max font size, image blocks with decorative flags) + images/ + rendered PNG of each page, preserving reading order via PyMuPDF's get_text('dict') block order.

daymade-docs/pdf-to-html/scripts/extract_pdf.py
The point of a separate extraction step is a *verifiable intermediate output*: structure.json is the plan. Inspect it (and the rendered page PNGs) before building, instead of going PDF -> HTML in one opaque jump.
Decorative heuristics: byte size < 3000 or the same bbox appearing across > half the pages (header/footer logos)—heuristically flagged and left to build to decide retention.

build_html.py is a data-driven general-purpose builder: it infers heading levels from font size distribution (most frequent size = body, larger sizes sequentially elevated to h3/h2/h1), strips decorative images, and compresses content images into base64-inlined assets—resulting in a single file openable with a double click.

daymade-docs/pdf-to-html/SKILL.md
`build_html.py` is **data-driven**: it infers heading levels from font size (most common size = body; larger steps up to h3/h2/h1), drops decorative images, and inlines content images as compressed base64 → one portable file. It is not hand-tuned to any document.
Images wider than 1400px are downscaled; wide photos convert to JPEG while line art remains PNG (PHOTO_WIDTH_THRESHOLD=1000/JPEG_QUALITY=82); unique layouts can be adjusted per document by inspecting the script.

The translation branch bypasses 'full-text machine translation'; instead, the agent follows references/translation_workflow.md using a Dynamic Workflow to translate pages in parallel, handle figures/captions separately, and unify terminology, producing two overlay files (units.json/caps.json) for build to consume.

daymade-docs/pdf-to-html/SKILL.md
It produces two overlay files (`units.json`, `caps.json`) that step 4 consumes. **Do not** hand-translate inline for anything longer than a page — the workflow keeps terminology consistent and is far faster.
Overlay text conventions (blank line = paragraph, '- ' = list, '## ' = subheading) allow translated text to be formatted; if the original lacks these markers, it flows as regular paragraphs.

Mandatory visual verification: verify_render.py takes screenshots using headless Chrome and slices them at ~2600px intervals (first probing real content height at 1x, then choosing the maximum device-scale-factor to avoid the 16384px screenshot limit); the agent must inspect each seg-*.png via Read.

daymade-docs/pdf-to-html/SKILL.md
```bash uv run --with Pillow --with numpy python scripts/verify_render.py output.html ``` Then **Read every `seg-*.png`** and check: fonts render (no tofu boxes), no clipped tables/figures, headings/lists look right, all expected images present.
The SKILL reminds that counting <figure> with grep requires -o | wc -l rather than grep -c (failure_cases #1); matching text does not equal matching rendering.

Ironclad fidelity rules are documented in references/failure_cases.md: never guess translations for personal or proper names, copy every number and proper noun verbatim (failure_cases #6), and read before translating.

daymade-docs/pdf-to-html/SKILL.md
The one that bites hardest: **never give a real person an inferred translated name, and copy every number/proper-noun verbatim** (failure_cases #6). Read that file before any translation run; skim it before any run.
Boundaries are also clearly defined: scanned files require OCR first, multi-column tables are flattened, no pixel-perfect clones, and no TL;DR summaries—'faithfulness is the point'.

2Core Capabilities

01PDF → Single self-contained, readable HTML (preserves images/tables/charts/reading order, base64-inlined)
02Infer heading levels from font sizes, filter decorative images, compress and inline (data-driven, no per-document manual tuning)
03PDF → Another language (preserves all figures and tables; overlay-driven + terminology consistency workflow)
04Inspectable intermediate structure: structure.json + page PNGs (inspect layout before building)
05Headless Chrome visual regression: slice-by-slice PNG verification (fonts/clipping/image completeness)
06Capability boundary management: documented trade-offs for scanned docs, multi-column tables, and pixel-perfect clones

3External Dependencies

KindDependency / Endpoint
packagePyMuPDF (fitz)(extract_pdf.py,uv run --with pymupdf)
cliGoogle Chrome / Chromium(headless 视觉验证)
packagePillow / numpy(build 与 verify,uv --with)

4Recommended Governance & Evidence

Suggested Controls for Safe Operation
For Agent Runtime
Graded/per-use authorization, sandbox recommended
For Administrators
Approval workflow, rollback support, full audit
Evidence & Triggers (File Paths & Excerpts)
  • scripts/: Execute local scripts or commands: python extract_pdf.py / build_html.py / verify_render.py (local extraction/building)
  • 外部端点: Exfiltrate local content or conversation to third-party cloud storage
  • 本地工作目录: File I/O and artifact output: input-build/ (structure.json, images/, pages/ per-page PNGs)
Audit Notes: Pure local Python + local Chrome rendering: zero network egress during runtime (verify even explicitly uses --no-proxy-server), zero credential reading, no deletion operations; only writes to the build directory and outputs HTML. Note: initial uv fetching of PyPI packages is a prerequisite step.

5Second-Pass Verification

  • [ok] extract→look→build→verify 管线 — SKILL 三步命令与三个脚本一一对应;structure.json 字段(bbox/字号/decorative)在 extract_pdf.py 实现。
  • [ok] 字号推断标题层级 — build_html.py 从 font size 推断 h3/h2/h1 的逻辑在 docstring 与代码中均有('larger sizes step up to h3/h2/h1')。
  • [ok] base64 内联单文件 — build_html.py data_uri():压缩→JPEG/PNG→base64;'single portable .html you can double-click' 相符。
  • [ok] decorative 判定启发式 — extract_pdf.py:DECORATIVE_MAX_BYTES=3000 + bbox 重复 > 半数页面(max(2, npages//2))。
  • [ok] 强制视觉验证 headless Chrome 分片 — verify_render.py:1x 探高 + device-scale-factor 选择 + SEGMENT_PHYSICAL 分片;SKILL 要求 Read every seg-*.png。
  • [ok] 翻译 overlay 机制 — translation_workflow.md 存在且描述 units.json/caps.json 产出;build_html.py 接受 --translation/--captions 参数。
  • [ok] 无网络外发/转义防注入 — 三脚本无 requests/urllib/http;build_html.py md() 对段落文本 html.escape;--no-proxy-server 防代理泄漏。
  • [ok] 元数据 — GitHub API:MIT / 1385 stars / pushed 2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678。

6Verdict & Scenarios

  • Reflowed readable HTML + complete preservation of figures/tables + single-file delivery provides the shortest path for 'reading a PDF'; the translation branch keeps even charts and captions intact.
  • Visual verification is mandatory and mechanized (Chrome sliced PNGs + reviewing each via Read), not just an informal recommendation.
  • The data-driven builder avoids hardcoded per-document logic, while still allowing script tweaks for irregular layouts on a per-document basis.
  • Documented failure cases and ironclad fidelity rules (no guessing proper nouns, copying numbers verbatim) prevent 'authoritative-looking hallucinations'.
  • Best for: Ideal for scenarios requiring 'turning a PDF into a readable single-file page on mobile or web without losing charts and figures' (e.g., reports to web pages, Chinese PDF translations, lecture note HTML); requires uv + Chrome installed and acceptance of two manual visual check gates: 'inspect pages before building, inspect rendering before delivery'.
    Not for: Not suitable for scenarios requiring editable plain text (choose doc-to-markdown); not suitable for pixel-perfect PDF replicas or cases where strict table grid lines must be preserved; not suitable for scanned documents without a text layer (run OCR first); not suitable for users demanding zero layout deviation post-translation.
    Install Agent-Ready
    ① Verified Mirror 2026-09-09
    Option A · Direct DownloadDownload pdf-to-html.tar.gz
    sha256: a8f3ffec2f8cdcaa…
    Option B · Copy Guide for Agent
    install.json
    Agents automatically download and verify mirrors from this JSON guide.
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit d5c4678cb5.