agentleFS
DBQDSSDBQDSS/aimath-translations-skill/skills/pdf-scanned-ocr-bookmark/SKILL.md

pdf-scanned-ocr-bookmark

Skill5 starsChanged 57 days agoMITView on GitHub

Add a searchable text layer and faithful heading bookmarks to image-only PDFs using available OCR tools. Use for individual or batch scanned AI/mathematics books; preserve originals and verify page geometry, OCR failures and saved destinations.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the shared terminology policy when editing generated titles.

    line 14
  2. Distinctive:

    Prefer usable span geometry over OCR, and OCR only the pages or regions that need it.

    line 23
  3. Distinctive:

    Use an available command-line or connected engine that supports the requested batching.

    line 32
  4. Distinctive:

    Keep page-specific OCR results and failures with input identity, page number, render DPI, engine/model configuration and any coordinate …

    line 37
  5. Distinctive:

    Start with conservative worker/thread counts and measure time and memory on samples.

    line 42
  6. Distinctive:

    Use the environment's supported background-job mechanism for long runs.

    line 43
  7. Distinctive:

    Use the installed PDF library's documented bookmark-destination API.

    line 84
  8. Distinctive:

    Keep source and output paths distinct while processing.

    line 90

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

OCR and bookmarks for scanned PDFs

Discover installed OCR engines, models, PDF tools and fonts before selecting a route. Use a copy of each input and validate saved output. This skill does not bundle a complete OCR pipeline; helpers named in historical projects are not dependencies.

Read the shared terminology policy when editing generated titles. Preserve source titles and human names, including accents; do not translate or transliterate a source name as an OCR cleanup operation.

Classify and render the input

Sample body pages across the book. One page of metadata text does not establish a usable text layer; some PDFs have text only in front matter. Check extraction directly, because a viewer's encoding error can resemble PDF corruption. Prefer usable span geometry over OCR, and OCR only the pages or regions that need it.

Choose render resolution from the source image's native dimensions, small glyphs and a sample comparison. Record the actual DPI per page or book. OCR geometry is in pixels; convert to points with 72 / actual_render_dpi. Preserve image rotation, crop boxes and the page transformation. A fixed 150/300 DPI is not universal.

OCR pipeline and recovery

Use an available command-line or connected engine that supports the requested batching. For RapidOCR/ONNX or another engine, inspect the installed API and model availability. Install dependencies only within the task's authorized environment; do not assume model packages run offline or request global upgrades unnecessarily.

Keep page-specific OCR results and failures with input identity, page number, render DPI, engine/model configuration and any coordinate transform. Cache using JSON or another safe serialization format where practical. Do not load untrusted pickle caches. Invalidate stale cache entries when inputs or configuration change.

Start with conservative worker/thread counts and measure time and memory on samples. Use the environment's supported background-job mechanism for long runs. Failed or empty pages need distinct states: a genuinely blank page is not an OCR failure. Retry only the failed pages after diagnosing the cause. If an engine repeatedly fails, switch to an available fallback or report the limitation.

On Windows, WinRT OCR can be an alternative when its language pack is installed. Load each required WinRT type explicitly, await asynchronous calls, and emit per-line or per-word geometry. Check failed calls and missing output instead of treating them as blank text. Other platforms need their own supported engine.

Build a faithful searchable layer

Insert invisible text using a font that covers the recognized script and appropriate line geometry. A Windows font path is only an environment-specific example; discover or supply an available font. Text insertion must not remove or alter original page images. Reopen the result and compare page count, size, rotation and sample renders.

Searchability is approximate: baseline insertion does not necessarily preserve word boxes, reading order or text fidelity. Record pages needing review. Do not claim “zero OCR errors” merely because every process returned successfully.

Locate bookmark headings

Parse the actual TOC and body headings. Reconstruct TOC rows from word/span geometry rather than trusting extraction order. Cluster by locally calibrated vertical gaps and column positions. Dedupe identical overlapping spans and distinguish dot leaders from the dot in a heading number. Preserve source order and existing bookmarks unless the requested repair requires replacing them.

Determine printed-to-physical page mapping from verified folios/body anchors, with separate segments for front matter, resets or inserts. Locate each heading within its expected window, excluding TOC pages and running headers. A matching title can repeat; the first search hit or neighbouring page is a candidate, not a confirmed target. For TOCs lacking pages, search sequentially within chapter boundaries and review ambiguity.

Classify hierarchy from source structure. Reject or flag unresolved/out-of-range destinations; do not clamp pages, sort away a wrong mapping, or invent a heading. See math-pdf-bookmark for text-geometry checks.

Save and verify

Use the installed PDF library's documented bookmark-destination API. PyMuPDF can accept a vertical offset or a fully specified destination dictionary depending on the supported form; an incomplete dictionary can create a dead link. Inspect get_toc(simple=False) after reopening output: require actual internal page destinations and check their coordinates visually.

Keep source and output paths distinct while processing. Preserve originals until validation is complete. Replace an original only if the user requested replacement, after all writers have finished and the output has reopened successfully. Do not force-copy a “usually intact” recovery file; validate it and retain the damaged copy when it may hold the only recoverable data. Limit batch validation to the requested corpus, and report OCR coverage, candidate headings, verified destinations and failures.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.