https://github.com/hitthecodelabs/pdfs_textreplacement
A Python utility for replacing specific text in a PDF file.
https://github.com/hitthecodelabs/pdfs_textreplacement
pdf pdfs python
Last synced: 8 months ago
JSON representation
A Python utility for replacing specific text in a PDF file.
- Host: GitHub
- URL: https://github.com/hitthecodelabs/pdfs_textreplacement
- Owner: hitthecodelabs
- License: mit
- Created: 2024-01-23T03:01:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-23T03:10:21.000Z (over 2 years ago)
- Last Synced: 2025-07-27T21:45:47.036Z (10 months ago)
- Topics: pdf, pdfs, python
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PDF Text Replacement and Reflow Project
This repository contains the `replace_text_and_reflow` function, a Python utility for replacing specific text in a PDF file and adjusting the text flow accordingly.
## Description
The `replace_text_and_reflow` function utilizes the PyMuPDF library to manipulate PDF files. It searches for a specified tag in the PDF, replaces it with provided text, and reflows the text to fit into the original layout.
## Installation
Before using this script, ensure that you have PyMuPDF installed:
```bash
pip install pymupdf
```
## Usage
Here's how you can use the `replace_text_and_reflow` function in your Python script:
```python
# Import the function
from replace_text_reflow import replace_text_and_reflow
# Define your parameters
pdf_path = 'example.pdf'
output_path = 'updated_example.pdf'
tag = 'TAG_TO_REPLACE'
replacement_text = 'New Text'
# Call the function
replace_text_and_reflow(pdf_path, output_path, tag, replacement_text)
```
### Parameters:
- `pdf_path`: Path to the original PDF file.
- `output_path`: Path where the modified PDF will be saved.
- `tag`: The text within the original PDF to be replaced.
- `replacement_text`: The text that will replace the `tag` in the document.
## Contributing
Contributions to improve the script or extend its functionality are welcome. Please feel free to fork the repository and submit pull requests.
## License
This project is licensed under the MIT License - see the LICENSE.md file for details.