Python CLI tool that replaces visible text in text-based PDF files.
- Replaces one or more words or short phrases in a PDF
- Saves the edited PDF as a new file
- Works best on selectable-text PDFs
- Keeps the original font, font size, color, and text baseline when the original PDF font can be safely reused
- Falls back to the closest built-in PDF font family when a custom embedded font would otherwise render invisibly
- Tries to keep nearby word spacing natural when a shorter replacement would otherwise leave an ugly gap
If you have a PDF and want to change a word inside it, this tool does that.
Example:
- Your PDF says
John - You want it to say
Jane - This tool opens the PDF, finds
John, and writesJanein the same place
You choose:
- which PDF to edit
- where the new edited PDF will be saved
- which word should change
- what the new word should be
The original PDF is not changed unless you overwrite it on purpose.
- Scanned/image-only PDFs are not supported unless OCR text already exists
- Complex layouts and text split across multiple drawing objects may still need manual review
- This tool replaces visible text areas; it is not meant for legal or tamper-proof redaction
- PDF line layout is not reflowed; longer replacements can overlap nearby content
- No automatic font shrinking or stretching is applied, so the output keeps the original text sizing
- Some embedded
Type0/Identity-H/ subset fonts may be replaced with the closest readable built-in PDF font instead of the exact original font
This tool uses two font modes:
- Direct reuse mode: if the PDF font can be safely reused, the tool keeps the original font style
- Safe fallback mode: if the PDF uses a risky custom embedded font, the tool writes the replacement with the closest readable built-in PDF font
- Standard PDF fonts such as
Helvetica,Times-Roman, andCourier - Many embedded
TrueTypefonts that PyMuPDF can reuse safely
If the original font cannot be safely reused, the tool maps it to one of the standard PDF families below.
Sans-style fonts map to the Helvetica family:
- Arial
- Helvetica
- Calibri
- Segoe UI
- Microsoft Sans Serif
- Verdana
- Tahoma
- Trebuchet MS
- Geneva
- DejaVu Sans
- Noto Sans
- Bitstream Vera Sans
- Frutiger
- Univers
- Gothic / KakuGo style names
Serif-style fonts map to the Times family:
- Times New Roman
- Georgia
- Garamond
- Cambria
- Baskerville
- Palatino
- Bookman
- DejaVu Serif
- Noto Serif
- Libertine
- Mincho / Song style names
Monospace fonts map to the Courier family:
- Courier New
- Consolas
- Monaco
- Lucida Console
- Menlo
- DejaVu Sans Mono
- Fira Code
- Source Code Pro
- JetBrains Mono
- IBM Plex Mono
Bold and italic styles are preserved when the original font name exposes that information.
python -m pip install -e .For tests:
python -m pip install -e .[dev]Open Windows PowerShell.
cd "C:\path\to\pdf-word-replacer"You only need to do this once:
python -m pip install -e .Basic format:
python -m pdf_word_replacer.cli "INPUT_PDF" "OUTPUT_PDF" --replace old=newWhat each part means:
INPUT_PDF= the PDF you want to editOUTPUT_PDF= the new PDF that will be created--replace old=new= change the wordoldintonew
python -m pdf_word_replacer.cli "C:\Users\Bugra\Documents\contract.pdf" "C:\Users\Bugra\Documents\contract-edited.pdf" --replace John=JaneThis means:
- open
contract.pdf - find
John - replace it with
Jane - save the result as
contract-edited.pdf
Replace a single word:
python -m pdf_word_replacer.cli "input.pdf" "output.pdf" --replace old=newReplace multiple words:
python -m pdf_word_replacer.cli "input.pdf" "output.pdf" --replace old=new --replace hello=worldReplace a phrase for cleaner layout:
python -m pdf_word_replacer.cli "input.pdf" "output.pdf" --replace "Meadow City=Garden City"Use case-insensitive matching:
python -m pdf_word_replacer.cli "input.pdf" "output.pdf" --replace old=new --ignore-caseUse this template and just change the file paths and words:
python -m pdf_word_replacer.cli "C:\PATH\TO\YOUR\INPUT.pdf" "C:\PATH\TO\YOUR\OUTPUT.pdf" --replace oldword=newwordExample:
python -m pdf_word_replacer.cli "C:\Users\Bugra\Desktop\file.pdf" "C:\Users\Bugra\Desktop\file-edited.pdf" --replace Apple=Orange- The tool reads the input PDF
- It searches for the word or phrase you gave
- It replaces the text in the PDF
- It saves a new PDF at the output path
If the command succeeds, you will see a message like this:
Saved: C:\path\to\output.pdf
Total replacements: 1
- John: 1
- If Python says the file does not exist, your PDF path is wrong
- If nothing changes, the PDF may be scanned or image-based
- If the new word is much longer, it may visually collide with nearby text
- If your path has spaces, keep it inside quotes like
"C:\My Folder\file.pdf"
python -m pdf_word_replacer.cli INPUT_PDF OUTPUT_PDF --replace SOURCE=TARGET [--replace SOURCE=TARGET ...] [--ignore-case]- The original file is not modified unless you choose the same input and output path
- The edited PDF is saved exactly where you tell the tool to save it
- Exact visual results still depend on how the original PDF stores its text