agentleFS
sulipapasulipapa/localize-infographic-pdf/SKILL.md

localize-infographic-pdf

Skill1 starsChanged 5 months agoMITView on GitHub

Localize a design-exported infographic / one-pager / poster PDF from one language into another (e.g. English to Chinese) while keeping the artwork pixel-identical: surgically remove the source text and redraw the translation in the same position, colour, weight and size. Use when the user gives a PDF (often a marketing one-pager, flyer, infographic, or poster, frequently landscape / multi-panel) and asks to translate / 本地化 / 翻译 / 汉化 / 做成中文版 / localize it while preserving the original images, charts, logos and layout ("保留原版图片和排版一模一样", "把英文换成中文", "出一版中文的"). Especially when the PDF was exported from a design tool so the text is vector outlines or Type3 glyphs that cannot be edited as text. NOT for plain text-extraction/translation of normal documents, nor for editable Word/PPT files.

  • Commits and pushes
  • In this repositoryOne other file it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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:

    Keep in source language by default: URLs, emails, brand/product trademarks, logos' baked text, bare numbers/units, and proper names.

    line 123

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

Localize Infographic PDF (artwork-preserving)

Produce a translated version of a design PDF that looks identical to the original except that every piece of running text is swapped to the target language. Works by rasterizing the page, erasing the source text, and compositing the translation back at the same coordinates — the artwork (photos, charts, gradients, icons, logos) is never regenerated.

Why this pipeline (read first)

Design-exported PDFs usually store the visible text as vector outlines (text-to-curves) or Type3 glyphs — it is NOT editable text, and there is no clean way to "replace the text". But these PDFs almost always also carry a hidden, searchable text layer whose word boxes are pixel-aligned with the visible text. That layer gives exact positions/sizes for free. So: do not try to edit text, and do not use a generative image model to "repaint" the background — that alters the artwork and cannot be pixel-faithful. Instead, cover-and-overlay: erase each source glyph run and redraw the translation in place. Background stays byte-faithful. See references/pipeline.md for the deeper rationale and failure modes.

Direction & mode — decide this at step 1

  • Direction is arbitrary. The engine is language-agnostic (EN→ZH, ZH→EN, JP→EN, …). Only the translator/verifier prompts and the default font assume a target — set them to the actual target, and override the font in overrides.json for non-CJK targets.
  • Overlay mode (default) — the artwork-preserving cover-and-overlay described here. Use when the PDF is genuinely a design (real artwork, vector/Type3 text) and the source is monolingual.
  • Clean-rebuild mode — when the source is already bilingual / mixed-language (each item already carries both languages) or is essentially a text document with little artwork, strict 1:1 overlay duplicates content: it can only cover text in place, it cannot delete or reflow lines, so translating a source line that sits next to an existing target-language line yields two near-identical lines. Instead rebuild: extract the content, drop the redundant source-language lines and any conversational artifacts (chat intros, "copy this into Word…" notes, working titles), and regenerate a clean target-only PDF (ReportLab or HTML→PDF), re-using the original logo/style (re-render the logo clip on white — a direct image extract flattens soft-mask transparency to black). Confirm the mode with the user when ambiguous. Details in references/lessons.md.

Workflow (run scripts in order from the skill's scripts/)

Pick a work dir (default loc_work). All scripts take SOURCE.pdf [OUTDIR] [PAGE].

  1. Analyze — 01_analyze.py SOURCE.pdf OUTDIR Confirms how text is stored, lists embedded images, renders the page. Look at the render and note any text that is baked into a chart/logo/photo image (it will NOT be in the text layer and must be handled as manual_labels).
  2. Extract — 02_extract.py SOURCE.pdf OUTDIR (env LOC_KEEP='brandA|brandB' to keep more strings in the source language). Produces units.json (one entry per physical text line, with bbox/colour/size) and translator_source.txt (a readable, id-tagged payload) + half_*.png.
  3. Translate — dispatch a translator agent. Give it translator_source.txt and half_0/1.png. It must write OUTDIR/translation.json = {"<id>":"译文", ...} covering every id (echo KEEP-AS-IS ids unchanged). Use the prompt in references/agent-prompts.md.
  4. Overrides (only if needed) — write OUTDIR/overrides.json for the per-document bits the auto-engine can't see: text baked into images (manual_labels), text inside thin stroked controls like pills/badges (solid_fill_labels), centered label zones (centered_id_ranges), and drop_ids. Schema + how to measure coordinates: references/overrides.md. Most simple flyers need no overrides; chart-heavy ones need a handful.
  5. Compose — 03_compose.py SOURCE.pdf OUTDIR → final_zh.png. This is the deterministic engine (background reconstruction + size-unified redraw). It needs no tuning per document.
  6. PDF + crops — 04_pdf.py SOURCE.pdf OUTDIR OUT.pdf → the PDF plus zh_L/zh_R.png for QA.
  7. Review & iterate (visual) — dispatch a reviewer agent to compare zh_L/zh_R.png against half_0/1.png (prompt in references/agent-prompts.md). This pass is visual: 套版保真 / residual source text / background integrity / font-size parity. Fix findings by editing overrides.json / translation.json and re-running 03→04. Repeat until clean. Typical issues and their fixes are listed in references/pipeline.md.
  8. Double-verify (independent second reviewer) — REQUIRED before delivery. The translator and the visual reviewer are the same model family and share blind spots (grammar, terminology drift, redundancy, mistranslation). Run a second, independent engine over the target-language text as a linguistic cross-check. Default engine: Codex (codex exec, read-only):
    python3 -c "import fitz,sys;open('OUTDIR/final.txt','w').write('\n'.join(p.get_text() for p in fitz.open('OUT.pdf')))"
    codex exec --skip-git-repo-check -s read-only -C OUTDIR - < verify_prompt.txt   # prompt below
    Prompt template ("Independent verifier") is in references/agent-prompts.md. Fold real findings back into translation.json / the rebuilt doc, regenerate, then re-run the verifier once to confirm (fixed / remaining / no-new-errors + a score). Keep judgement — reject stylistic nits that fight source fidelity; do not apply blindly. Two independent reviews = the 双重校验 gate.
  9. Retro & self-update — do this on every real run. Each localization exposes gaps the skill didn't cover. Before finishing: append what was missing/awkward to references/lessons.md, fold the actionable items into the skill (SKILL.md / scripts / references), then git commit + git push. The skill must get a little better each time it runs. Read references/lessons.md at the start of a run too — it flags known edge-cases so they aren't rediscovered.

The 4-role loop (translator → compositor → visual reviewer → independent verifier) mirrors a human localization team: the reviewer (1–2×) catches the layout long tail; the independent verifier catches language issues a same-family reviewer misses.

What the engine handles automatically (no config)

  • Light-text-on-dark AND dark-text-on-light panels (picks the right background colour).
  • Flat panels, smooth gradients, and photo backgrounds (chooses fill vs inpaint per region).
  • "Ghost" text-layer entries that have no visible glyphs (auto-skipped — never drawn).
  • Bulleted lists where the bullet got swallowed into the first row's box (auto-realigned).
  • Font size: original size, unified per block so wrapped paragraphs/quotes don't go ragged.

Defaults & requirements

  • Python: pymupdf (fitz), numpy, opencv-python (cv2), Pillow.
  • CJK font default Hiragino Sans GB.ttc (macOS; W3 regular idx 0 / W6 bold idx 2). Override via overrides.json "font" for other languages/fonts.
  • Render scale default 6.0 (≈432 dpi). Lower to 4 for speed while iterating; raise for print.
  • Keep in source language by default: URLs, emails, brand/product trademarks, logos' baked text, bare numbers/units, and proper names. The translator decides; the KEEP regex pre-flags the obvious.

Reference files

  • references/pipeline.md — rationale, the removal strategy decision tree, and a catalogue of common visual defects with their exact fixes (streaks, residue, broken pills, size collapse).
  • references/agent-prompts.md — ready-to-paste translator, visual-reviewer, and independent-verifier prompts.
  • references/overrides.md — overrides.json schema and how to measure chart/pill coordinates.
  • references/lessons.md — running log of edge-cases and shortcomings from real runs (read at start; append at end).

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.