$npx -y skills add superpilot69/pdf-trad-to-simp-preserve-layout-kit --skill skillConvert traditional Chinese PDFs to simplified Chinese while preserving page size, images, selectable text, and overall layout as much as possible. Use when Codex is asked to directly convert a source PDF from 繁体 to 简体 without rebuilding the book, to keep the original PDF structu
| 1 | # PDF Trad To Simp Preserve Layout |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill when layout fidelity matters more than reflowed typography. The bundled scripts keep the original PDF page geometry and images, replace only the text layer on text-based pages, and handle image-only cover pages as a separate replacement step. |
| 6 | |
| 7 | ## Follow This Workflow |
| 8 | |
| 9 | 1. Inspect whether the PDF already has a usable text layer. |
| 10 | - Run `pdftotext -f 5 -l 5 input.pdf - | sed -n '1,20p'`. |
| 11 | - If you get readable text, use `scripts/convert_pdf_t2s_preserve_layout.py`. |
| 12 | - If the whole file is scan-only, stop and use OCR first. This skill is not an OCR workflow. |
| 13 | |
| 14 | 2. Choose a full Chinese font before writing simplified text back into the PDF. |
| 15 | - Do not reuse the source PDF's embedded subset font. Many book PDFs embed only the traditional glyph subset, so simplified text will render incorrectly or disappear. |
| 16 | - Prefer a lighter Songti-style font for book body text. |
| 17 | - On macOS, extract a face from `Songti.ttc` with `scripts/extract_ttc_font.py`, or let the converter auto-detect it. |
| 18 | |
| 19 | 3. Install the bundled dependencies once. |
| 20 | |
| 21 | ```bash |
| 22 | SKILL_DIR="${CODEX_HOME:-$HOME/.codex}/skills/pdf-trad-to-simp-preserve-layout" |
| 23 | "$SKILL_DIR/scripts/install_deps.sh" |
| 24 | source "$SKILL_DIR/.venv/bin/activate" |
| 25 | ``` |
| 26 | |
| 27 | 4. Convert the text layer without rebuilding the book. |
| 28 | |
| 29 | ```bash |
| 30 | python "$SKILL_DIR/scripts/convert_pdf_t2s_preserve_layout.py" \ |
| 31 | input.pdf output.pdf \ |
| 32 | --font-style light |
| 33 | ``` |
| 34 | |
| 35 | - Pass `--font-path /path/to/font.ttf` if you already have a suitable full font. |
| 36 | - Pass `--font-ttc /path/to/Songti.ttc --font-style regular` to override automatic font discovery. |
| 37 | - Use `--font-size-scale` or `--baseline-y-shift` only for small visual tuning passes. |
| 38 | |
| 39 | 5. Replace image-only cover pages separately when needed. |
| 40 | |
| 41 | ```bash |
| 42 | python "$SKILL_DIR/scripts/replace_pdf_cover.py" \ |
| 43 | output.pdf final.pdf cover.png |
| 44 | ``` |
| 45 | |
| 46 | - Use this when the cover is a full-page image and therefore cannot be fixed by text-layer replacement. |
| 47 | - The replacement preserves page count and the rest of the document. |
| 48 | |
| 49 | 6. Verify the result before declaring success. |
| 50 | - Run `pdfinfo final.pdf`. |
| 51 | - Run `pdftotext -f 9 -l 9 final.pdf - | sed -n '1,20p'`. |
| 52 | - Render a few pages and compare cover, body text weight, and image pages. |
| 53 | - Read [references/workflow.md](references/workflow.md) for troubleshooting and a more detailed checklist. |
| 54 | |
| 55 | ## Use These Bundled Tools |
| 56 | |
| 57 | - `scripts/install_deps.sh`: Create a skill-local virtual environment and install the required Python packages. |
| 58 | - `scripts/extract_ttc_font.py`: List or extract faces from a `.ttc` collection. |
| 59 | - `scripts/convert_pdf_t2s_preserve_layout.py`: Convert text-layer pages from traditional to simplified Chinese while preserving layout as much as possible. |
| 60 | - `scripts/replace_pdf_cover.py`: Replace a cover or other full-page image page without disturbing the rest of the PDF. |
| 61 | - `references/workflow.md`: Read for preflight checks, font choices, failure modes, and verification steps. |