pdf-cid-extract
When to use
- A PDF on this machine is too large for the Read tool (>256KB) and you need its text.
pip install pypdffails (corp TLS-intercepting proxy returns empty index;清华 mirror also blocked).- The PDF text is CID/Identity-H encoded (ToUnicode CMap), so naive
(...) Tjextraction yields garbage or empty. - Git Bash here lacks
head/tail/dirname— avoid piping to them; use python- <<'PYEOF'heredocs.
Method (pure stdlib)
- Read file bytes.
- Find every
stream ... endstream, brutezlib.decompress(strip trailing EOL before endstream). - Among decompressed streams, parse ToUnicode CMaps:
beginbfchar/endbfcharandbeginbfrange/endbfrange→ buildcid_int -> char. - Extract text-show ops. Both forms matter: literal
(...)and hex<...>strings. CID fonts often use<0041> Tj/[<...>] TJ. - Decode: if a string is >85% printable ASCII, treat as latin-1 single-byte; else decode as 2-byte big-endian CIDs via the map (unmapped <128 → chr, else '?').
Known artifacts
- Some Chinese-corpus PDFs show a systematic letter shift in the extracted prose (e.g. displayed "Fsolation" = "Isolation", "Bigital" = "Digital"). Digits/numbers are usually intact. Read numbers & structure literally; correct obvious letter shifts by eye.
- Pin-number columns can be corrupted → do a final visual check of Pin-1 on the real landing pattern before trusting pinout.
Reusable script
See scripts/extract_cid_pdf.py in this skill's directory (run: python scripts/extract_cid_pdf.py <file.pdf> → prints unique text fragments to stdout; optional second arg caps output lines).