TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

BaseMax / PDFSmartEdit

Edit and replace text in PDFs with Python and PyMuPDF - simple, fast, and accurate text replacement that keeps the original font and style.

1 0 Language: Python License: MIT Updated: 5mo ago

README

๐Ÿ“ PDF Smart Edit

A lightweight Python tool to search and replace text in PDF files using PyMuPDF (fitz).
It allows you to programmatically replace specific text strings while preserving the original font and size as much as possible.


๐Ÿš€ Features

  • ๐Ÿ” Find and replace text inside PDF files
  • ๐Ÿง  Automatically detects and reuses font and text size
  • ๐Ÿงน Cleans up and redraws replaced text neatly
  • โš™๏ธ Supports font aliasing (e.g. Arial โ†’ helv)
  • ๐Ÿ“„ Easy configuration for multiple replacements
  • โœ… Works fully offline (no Adobe or APIs required)

๐Ÿ“ฆ Requirements

Before running the script, install the following dependencies:

pip install PyMuPDF

Or, if you use requirements.txt:

pip install -r requirements.txt

๐Ÿ’ก Usage

  1. Place your source PDF in the same directory (e.g. input.pdf).
  2. Edit the replacement rules inside script.py:
REPLACEMENTS = [
    {"old_text": "11/10/2025", "new_text": "22/10/2025", "max_replace": 1},
    {"old_text": "10/10/2025", "new_text": "22/10/2025", "max_replace": 1},
]
  1. Run the script:
python script.py
  1. The edited PDF will be saved as output.pdf.

๐Ÿง  Example Output

๐Ÿ”น Processing page 1...
   โœ… '11/10/2025' โ†’ '22/10/2025' (1x, font=helv, size=11.0)
   โœ… '10/10/2025' โ†’ '22/10/2025' (1x, font=helv, size=11.0)

๐ŸŽ‰ Done! Saved edited PDF โ†’ output.pdf

โš™๏ธ Configuration Details

REPLACEMENTS

A list of dictionaries, each defining:

  • old_text: The text to search for.
  • new_text: The text to replace it with.
  • max_replace: (optional) Maximum number of occurrences to replace per page.

Example:

REPLACEMENTS = [
    {"old_text": "Draft", "new_text": "Final", "max_replace": 2},
]

Fonts

The script automatically detects the font used near the target text.
It includes built-in font aliases to ensure compatibility:

Original Font Internal Alias
Arial, Calibri, Helvetica helv
Times-Roman, TimesNewRoman times
Courier cour

If an unknown font is detected, it defaults to helv (Helvetica).


๐Ÿงฐ Project Structure

edit-pdf-online/
โ”œโ”€โ”€ script.py        # Main Python script
โ”œโ”€โ”€ input.pdf        # Example input file (you provide)
โ”œโ”€โ”€ output.pdf       # Generated after running the script
โ”œโ”€โ”€ README.md        # Project documentation
โ”œโ”€โ”€ LICENSE          # MIT License
โ””โ”€โ”€ .gitignore

๐Ÿง‘โ€๐Ÿ’ป Author

Seyyed Ali Mohammadiyeh (Max Base)
๐ŸŒ https://github.com/BaseMax


๐Ÿ“œ License

This project is licensed under the MIT License.


๐Ÿ’ฌ Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open an issue or a pull request.


โญ Support

If you find this project helpful, please consider giving it a โญ on GitHub!

0 AIs selected
Clear selection
#
Name
Task