Skip to main content

A PDF cropping utility for removing headers, footers, and margins from multiple pages at once.

Project description

PyCropPDF

PyCropPDF is a desktop application designed to crop and mask PDF files. It is particularly suited for documents where multiple pages share a common layout structure—such as scanned books, academic papers, or reports—allowing you to remove margins, headers, footers, or watermarks across many pages simultaneously.

PyCropPDF Screenshot

Key Concepts

1. Transparent Overlay Preview

Instead of showing pages one-by-one, PyCropPDF renders and overlays page previews transparently on top of each other. This enables you to visually check that a selected crop boundary or whiteout mask fits every page in the document (or group of pages) without clipping text or diagrams.

2. View Modes

  • All Pages (Overlay): Overlays all document pages together. Helpful for verifying margins across the entire document.
  • Odd / Even Pages: Splits the preview into two separate overlays—one for odd pages and one for even pages. This is useful for double-sided documents (like bound books) where the left and right margins alternate.
  • Single Page Preview: Focuses on a single page, allowing you to fine-tune boundaries for specific layout exceptions.

3. Crop vs. Whiteout Tools

  • Crop Box: Defines a bounding box. When applied, pages are cropped to this box (modifying the PDF page's physical boundaries).
  • Whiteout Mask: Applies solid rectangular overlays (masks) to cover page content. You can choose a custom color to match the page background.

4. Page Selection & Deletion

A sidebar displays thumbnails of all pages.

  • Multi-selection is supported using Ctrl + Click (toggle individual pages) and Shift + Click (select a range of pages).
  • Operations (cropping and whiteout) can be limited to the selected pages.
  • Selected pages can be deleted from the document.
  • Operations can be undone step-by-step.

5. Provenance Manifests

When you save a modified PDF, the application generates a JSON sidecar manifest (e.g., document_modified.pdf.pycroppdf.json). This manifest records:

  • SHA-256 hashes of the source and output PDF files.
  • Original page counts and mapping of output pages to original pages.
  • Explicit lists of deleted page indices.
  • Exact coordinates and dimensions of crops and whiteouts applied.

This manifest enables downstream automated pipelines to trace the history and modifications of the edited PDF back to its original source.


Installation

Prerequisites

  • Python 3.8 or higher.

Installation from PyPI

You can install PyCropPDF directly using pip:

pip install pycroppdf

Installation from Source (Development Mode)

To clone the repository and install it in editable mode for development:

git clone https://github.com/lukaszliniewicz/PyCropPDF.git
cd PyCropPDF
pip install -e .

Usage

Start the graphical interface from the terminal:

pycroppdf

To start the interface with a PDF already loaded:

pycroppdf --input /path/to/document.pdf

Command-Line Arguments & Automation

The application accepts arguments to pre-configure paths and manifest outputs:

  • --input /path/to/file.pdf: Loads the specified PDF at launch.
  • --save-to /path/to/directory/: Specifies the folder where the edited PDF will be saved.
  • --save-as filename.pdf: Specifies the filename for the output PDF.
  • --manifest-out /path/to/output.json: Overrides the default location for the JSON provenance manifest.

Note: If --save-to or --save-as is specified, the standard "Save File" dialog is bypassed. Clicking "Save PDF..." immediately saves the file to the pre-configured path.

Basic Edit Workflow

  1. Open a PDF: Drag and drop a PDF file into the window, or go to File > Open PDF....
  2. Select View Mode: Choose All, Odd/Even, or double-click a page thumbnail to view a single page.
  3. Apply a Crop: Select the Crop Box tool, click and drag a box on the canvas, and click Apply Crop. If odd/even mode is active, you can define separate boxes for odd and even pages.
  4. Apply a Whiteout: Select the Whiteout tool, click and drag to cover text/images.
  5. Manage Pages: Select thumbnails in the sidebar to delete unnecessary pages.
  6. Undo Changes: Use the Undo button or Ctrl + Z to revert your actions.
  7. Save: Click Save PDF to export the modified document and its provenance manifest.

Development & Building

Running Unit Tests

Install pytest and execute it from the project root:

pytest

Building a Standalone Executable

You can compile PyCropPDF into a standalone executable using pyinstaller. From your environment, run:

pyinstaller --onefile --noconsole --name PyCropPDF run.py

This produces a single, self-contained executable file inside the dist/ directory.


License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycroppdf-0.2.1.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycroppdf-0.2.1-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file pycroppdf-0.2.1.tar.gz.

File metadata

  • Download URL: pycroppdf-0.2.1.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pycroppdf-0.2.1.tar.gz
Algorithm Hash digest
SHA256 816a8f7b30286e2cf4f92c56528f53fe458f1c04b9f71fed7748a55c7897373f
MD5 96a7d8e6e2ad0c2d27147c9a405098f4
BLAKE2b-256 a31f829613fcbf4635c6ab5052f8d2ad75a5d5b2332fafdf4e910f8b092ae212

See more details on using hashes here.

File details

Details for the file pycroppdf-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pycroppdf-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pycroppdf-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e65ceae18899bb81f614793d571748c5ec009e504c504d52ddfc16d63afc8ec5
MD5 4514cdd92d5f05f969bbd4e0d9021991
BLAKE2b-256 965c99f0efdcc26943d29fb87783d0363c2c6c1ff9fd2bc84db754f9d4008abf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page