What is krop?
krop is a simple graphical tool to crop the pages of PDF files.
How about a brief guided tour & screenshots?
- krop should work on any recent Linux distribution, see how to install krop. I don't know if krop can be used on Windows or Mac after a sufficient amount of tinkering: please let me know in case you succeed.
- It is written in Python and relies on PyQt and PyMuPDF (or a suitable subset of pypdf/pikepdf/python-poppler-qt) for its functionality.
- It is free software, released under GPLv3+ in the sole hope that you or someone else may find it useful.
- A unique feature of krop, at least to my knowledge, is its ability to automatically split pages into subpages to fit the limited screensize of devices such as eReaders. This is particularly useful, if your eReader does not support convenient scrolling. (In fact, I initially wrote krop to be able to read mathematical papers on my Nook.)
- Please report bugs or feature requests at https://github.com/arminstraub/krop where the source code for krop is hosted.
What krop fails to do
Unfortunately, there is no simple way to eliminate unnecessary/invisible parts of a PDF file. krop only adjusts which parts of a PDF are displayed; the original content is still there in the file and will, for instance, show up when editing the file in inkscape. As a result, krop is not suited for
- censoring a PDF document or
- decreasing the size of a PDF file.
That being said, since version 0.5.0, you may have some success in decreasing the size of the PDF (and even censoring some parts) using the option to use Ghostscript to optimize the final PDF.
Changelog
krop 0.7.0 | 2025/04/06 | Armin Straub | |
+ | Support PyQt6 and update packaging (thanks to PunkPangolin for this work). | ||
+ | Support PyMuPDF for rendering and cropping. | ||
+ | Support pikepdf for cropping (thanks to Hongzhuo Liang for the idea and initial code). | ||
* | Support the new version of pypdf in addition to its predecessor PyPDF2 (thanks to Emmanuel Rosa for the idea and initial code). | ||
* | Support both old (<2) and new (>=2) versions of PyPDF2 (thanks to milahu for the idea and initial code). | ||
* | When using PyPDF2, preserve links within a PDF (thanks to chrthi for this). | ||
* | Display PDF file name in window title. | ||
krop 0.6.0 | 2020/06/09 | Armin Straub | |
+ | Fixed aspect ratios, like letter size, can be chosen for selections. | ||
+ | Selections (or a grid of selections) for the full page can now be created using the context menu or by pressing Insert (or Shift+Insert). Also introduced the command line option --grid to create a grid of selections on the initial page. | ||
+ | Auto trimming margins can now inspect all pages. | ||
+ | New option for whether to include pages without selections in the output. | ||
+ | Added the command line options --optimize (thanks to Ondrej Tichacek for suggesting this feature) and --exceptions. | ||
+ | Implemented several keyboard shortcuts including Shift+Arrow to move current selection and Delete to remove it. | ||
* | Keep track of current selection and highlight it visually. | ||
* | Don't fail on PDFs that are encrypted with an empty password. | ||
* | Remember window geometry and fit in view setting. | ||
krop 0.5.1 | 2018/10/27 | Armin Straub | |
* | Replace and extend the README file with a MarkDown version (thanks to Eduardo Montenegro for doing this). | ||
+ | Add a manpage. | ||
* | Fix a Qt5 related bug when selecting filename for saving (thanks to Lin-Buo-Ren for reporting this). | ||
More ... |
Source code and testing krop
The source code for krop is now hosted on GitHub: https://github.com/arminstraub/krop
To download and run krop without installing, you can proceed as follows:
$ git clone https://github.com/arminstraub/krop.git $ cd krop $ python3 -m krop
Previously, I posted snapshots of the releases here as tarballs. You can download such snapshots from GitHub. For instance, to download krop-0.7.0.tar.gz, the tarball for the most recent release:
$ wget -O krop-0.7.0.tar.gz https://github.com/arminstraub/krop/archive/v0.7.0.tar.gz
Install krop
krop is available in the official repositories of several linux distributions, including the following, ready to install with a single command.
- Debian, Ubuntu, Kubuntu, Linux Mint:
sudo apt install krop
- Gentoo:
sudo emerge krop
- Fedora:
sudo yum install krop
- Packages also exist for Arch Linux and Slackware.
- krop can also be installed as a snap or a flatpak.
Note that the version of krop in these repositories may not always be the most recent. In that case, or if your distribution doesn't include krop, you can follow the instructions in the next section to install the most recent version directly.
Install krop using pipx
Assuming you have pipx installed on your system, you can install the most recent version of krop from GitHub as follows:
$ pipx install --system-site-packages git+https://github.com/arminstraub/krop
You can now run the command krop. You will receive complaints if you are missing prerequisites, namely PyQt and PyMuPDF (or a suitable subset of pypdf/pikepdf/python-poppler-qt).
On Kubuntu 22.04/24.04, for example, you can install pipx as well as these prerequisites using:
$ sudo apt install pipx python3-pyqt5 python3-fitz
The package python3-fitz contains the Python library PyMuPDF which can both display and crop PDFs. If you prefer, you can replace this package by both of python3-poppler-qt5 (for displaying PDFs) and python3-pypdf2 (for cropping).
You can uninstall krop using:
$ pipx uninstall krop
A few notes:
- The
--system-site-packages
flag allows krop to use the PyQt5 library as well as the PDF viewing and cropping libraries that are installed on your system. On the other hand, if you prefer to run krop in an isolated environment, you can proceed as follows instead:$ pipx install git+https://github.com/arminstraub/krop $ pipx inject krop PyQt5 $ pipx inject krop PyMuPDF
- If you want to also install the icons and the desktop file (for integration into the context menus, application launcher, ...) you might find the following instructions by Jeff Kowalski helpful.
- On a Kubuntu 22.04 machine, I ran into an issue where pipx (only when using the
--system-site-packages
flag) complained that TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'. To still use the system packages, the following worked for me:$ pip3 install git+https://github.com/arminstraub/krop --user
Hints for advanced usage
- Basic keyboard shortcuts are supported: you can navigate the PDF file using PageUp/PageDown and Home/End, you can create and delete selections using Insert/Delete. You can also move the current selection using the arrow keys while pressing Shift.
- If you are cropping a PDF file with many pages, then you may have some exceptional pages which need to be cropped in a different way then the other pages. In that case, the option Exceptions under Selections apply to will be useful to you.
- If you press Trim Margins on a page without selections, then
krop
will automatically create a region for the full page with the margins trimmed. - You can use command line arguments in addition to (or, to a degree, instead of) the graphical interface.
Run
krop --help
to get a list of all possible arguments. For instance, to automatically undo 4 pages print onto a single page:$ krop --go --grid=2x2 file.pdf
Omit the--go
to open the GUI with the 2x2 grid of selections pre-created. To additionally trim each of these pages:$ krop --go --grid=2x2 --trim --trim-use=all file.pdf
Prefix these commands withxvfb-run
(in the packagexvfb
on Debian/Ubuntu) if you are not running an X server. - You can add entries to the default aspect ratios offered in the dropdown boxes for Current Selection and Fit screen of device by editing the configuration file. The location of this file may differ from system to system, but a good place to start looking is ~/.config/arminstraub.com/krop.conf. In that file, edit the entries for
SelAspectRatiosDefaults
andDeviceTypesDefaults
and change the header toSelAspectRatios
andDeviceTypes
(that is, removeDefaults
from the header). Don't forget to adjust the countersize=
after adding new entries. - If you run into the error multiple definitions in dictionary while cropping a file, then this is because pyPdf is too strict. You can either upgrade to PyPDF2 or proceed as indicated in this bug report.
TODOs: roadmap and wishlist
Roadmap (ideas planned for one of the next releases) | |
+ | Improve support for pikepdf, PyMuPDF and pypdf (e.g. preserve links) |
+ | Support QtPy, an abstraction layer for both PyQt and PySide (for Qt5 and Qt6) |
+ | Expose further Ghostscript features (like exporting to PDF 1.7) |
+ | Save and later reuse regions for cropping |
+ | Use parallel processing for certain tasks like cropping |
+ | Allow translations (once UI has stabilized) |
Wishlist (ideas that are likely difficult or currently impractical) | |
+ | Preserve meta data, table of contents and bookmarks when cropping |
+ | Option to overlay pages in order to improve making selections |