A command-line tool that converts PDF files into image-based documents, effectively making them resemble scanned documents. This process removes any interactive elements, forms, or embedded content while preserving the visual appearance. Ideal for creating consistent, non-editable versions of documents or preparing them for archiving.
- Converts PDFs to image-based documents, simulating scanned documents
- Preserves original metadata, including MacOS timestamps
- Allows for setting of custom creation and modification dates
- Configurable DPI settings for quality control
- Cross-platform support (Windows, macOS, Linux)
- Poppler: Required for PDF processing
- macOS:
brew install poppler - Linux:
sudo apt-get install poppler-utils - Windows: Download and install from poppler releases
- macOS:
- Python 3.10 or higher
- Required Python packages (automatically installed via pip):
- PyMuPDF (fitz)
- pdf2image
-
Clone the repository:
git clone https://github.com/Tomek20225/pdf-flattener.git cd pdf-flattener -
Install dependencies:
pip install -r requirements.txt
-
Build the executable:
make build
-
(Optional) Install globally:
sudo make install
Download the latest release from the Releases page for your operating system.
Basic usage:
flatten_pdf input.pdfAdvanced usage with options:
flatten_pdf input.pdf --output output.pdf --dpi 300 --creation-date 2024-01-01 --modification-date 2024-01-02input_pdf: Path to the input PDF file (required)--output,-o: Output PDF file name (default: "flat-{input_filename}")--dpi,-d: DPI for image extraction (default: 200)--creation-date,-c: Creation date in YYYY-MM-DD format--modification-date,-m: Modification date in YYYY-MM-DD format
# Build the executable
make build
# Install globally
make install
# Clean build files
make clean
# Full rebuild and install
make reinstallpip install -r requirements.txt
pyinstaller --onefile flatten_pdf.pyThe project includes a comprehensive test suite using pytest. To run the tests:
-
Install test dependencies:
pip install -r requirements.txt
-
Run the tests:
pytest tests/
Tests use temporary files and directories that are automatically cleaned up after each test run.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses the following open-source libraries:
If you encounter any issues or have questions, please open an issue on GitHub.