Coder Social home page Coder Social logo

arminstraub / krop Goto Github PK

View Code? Open in Web Editor NEW
115.0 7.0 16.0 172 KB

A simple graphical tool to crop the pages of PDF files, written in Python/Qt

Home Page: http://arminstraub.com/software/krop

License: GNU General Public License v3.0

Python 98.37% Roff 1.63%
crop pdf-files ebook-readers

krop's People

Contributors

alexmyczko avatar arminstraub avatar edumco avatar har9862 avatar heirecka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

krop's Issues

ValueError: PyCapsule_GetPointer called with incorrect name

Whenever I try to run either the Ubuntu Universe packaged version of the app or the snap version in Lubuntu 19.10, I receive the following error:

ValueError: PyCapsule_GetPointer called with incorrect name

The error described here:

https://github.com/leo-editor/leo-editor/issues/1106

... was similar, so I tried applying the fix there to the latest code from the git repo (without a full understanding of the issue). I have added the following to vieweritem.py at line 25:

except ValueError: QtWebKitWidgets = None

I then ran:

python3 setup.py build
sudo python3 setup.py install

Krop now runs for me.

python 3.10

Is there going to be python310 support?

Traceback (most recent call last):
  File "/usr/bin/krop", line 33, in <module>
    sys.exit(load_entry_point('krop', 'console_scripts', 'krop')())
  File "/usr/bin/krop", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 919, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 518, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for krop

macOS Support

I am just opening this issue to be notified if macOS ever gets supported.

BTW: Have you seen https://www.willus.com/k2pdfopt/? It's pretty good, though I mostly use it for non-mathy PDFs. It doesn't play that well with equations that take multiple vertical lines.

Show equivalent command line of GUI configuration

I would be very useful if the GUI could show the equivalent command line that give the same resoult of what you are doing with the GUI.

Whit this feature you could decide how crop your pdf using GUI (which is more visual an easy in order to decide the area to crop) but later you could build a script to repeat the job in future without having to repeat everything from the beginning.

Preserve Table of Contents

What a great little app!

However, after processing a pdf with krop, the table of contents "metadata" seems to be deleted. Is there any way to retain it? (makes sense for ereaders too, navigating to a specific part is especially cumbersome on slower and smaller devices if you can't just select a chapter)

Even python-pypdf2 is installed, I still get error messages in Manjaro

Hi,

I installed from AUR using yay in Manjaro.
This is the output that I get:

$ krop

(python:9314): Gtk-WARNING **: 22:00:05.427: Unable to locate theme engine in module_path: "clearlooks",

(python:9314): Gtk-WARNING **: 22:00:05.428: Unable to locate theme engine in module_path: "clearlooks",
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/krop/pdfcropper.py", line 28, in <module>
    from pyPdf import PdfFileReader, PdfFileWriter
ModuleNotFoundError: No module named 'pyPdf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/krop", line 33, in <module>
    sys.exit(load_entry_point('krop', 'console_scripts', 'krop')())
  File "/usr/lib/python3.10/site-packages/krop/application.py", line 81, in main
    from krop.mainwindow import MainWindow
  File "/usr/lib/python3.10/site-packages/krop/mainwindow.py", line 46, in <module>
    from krop.pdfcropper import PdfFile, PdfCropper, PdfEncryptedError, optimizePdfGhostscript
  File "/usr/lib/python3.10/site-packages/krop/pdfcropper.py", line 34, in <module>
    raise RuntimeError(_msg)
RuntimeError: Please install PyPDF2 (or its predecessor pyPdf) first.
	On recent versions of Ubuntu, the following should do the trick:
	sudo apt-get install python-pypdf2
	(or, if using python3) sudo apt-get install python3-pypdf2

I am totally sure that python-pypdf2 is installed:

$ yay -Ss python-pypdf
aur/python-pypdf3 1.0.5-1 (+0 0.00) 
    Pure-Python PDF library for splitting, merging, cropping, and transforming PDF pages.
aur/python-pypdf2-git b17382f-1 (+5 0.00) 
    PyPDF2 library for Python3
aur/python-pypdf2 1.26.0-2 (+20 1.23) (Installed)
    A utility to read and write PDFs with Python

Is there a workaround, something like softlinking to the already installed library?

Better installation method

A better and more portable installation method:

  1. install pipx
  2. install krop: pipx install krop
  3. install dependencies: pipx inject krop python-poppler-qt5 pypdf2

error has occured: file has not been decrypted

Hi developers,
Thank you for this tool!
I found some PDF files can't be cropped, with this error:

The following unexpected error has occured:
file has not been decrypted

In console

Traceback (most recent call last):
  File "krop-0.5.1/krop/mainwindow.py", line 340, in slotKrop
    raise err
  File "krop-0.5.1/krop/mainwindow.py", line 315, in slotKrop
    cropper.addPageCropped(pdf, nr, c, rotate=rotation)
  File "krop-0.5.1/krop/pdfcropper.py", line 86, in addPageCropped
    page = pdffile.reader.getPage(pagenumber)
  File "/usr/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1176, in getPage
    self._flatten()
  File "/usr/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1505, in _flatten
    catalog = self.trailer["/Root"].getObject()
  File "/usr/lib/python3.6/site-packages/PyPDF2/generic.py", line 516, in __getitem__
    return dict.__getitem__(self, key).getObject()
  File "/usr/lib/python3.6/site-packages/PyPDF2/generic.py", line 178, in getObject
    return self.pdf.getObject(self).getObject()
  File "/usr/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1617, in getObject
    raise utils.PdfReadError("file has not been decrypted")
PyPDF2.utils.PdfReadError: file has not been decrypted

fx_82TL_350TL.pdf

Any plans to support Windows?

I find the feature set of krop quite interesting and because at my job I have to work with Windows, I'd interested whether there are any plans on supporting the Windows platform as well?

It could be possible to use an automated *.exe creation mechanism like some other projects (e.g. neovim uses appveyor - see the config file).

Krop "refuses" to save

Started Krop and followed instructions as per the "Help" menu tab: open pdf file, create selection: ok.
Buttons Zoom, Previous, Next and Trim all work as expected.
Clicked the Krop! button [smiling face :-)] and expected a File Save Dialog to save the cropped pdf, but nothing happened.
Tried different distributions (Snap, Flatpak and Apt): no difference (except that the Apt-version is rather old).
Also started krop from the command line to view possible error messages but nothing shows when pressing the Krop! button.
Any tips welcome!

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"

Krop also available as flatpak

just a small info: there is also a flatpak for krop available at flathub ...

PS: Ganz herzlichen Dank für das Tool ...

config.py references non-namespaced sip module

config.py curently includes code:
krop/config.py: import sip
krop/config.py:sip.setapi('QString', 2)
krop/config.py:sip.setapi('QVariant', 2)

Not sure it's purpose, but recent sip/PyQt5 releases use a name-spaced PyQt5.sip module instead. So either drop this or switch to PyQt5.sip (depends if the setapi calls are really needed anymore or not)

Expose Optimize PDF option in command line client [feature request]

I would like to use krop for automatic trimming of a bunch of images via the command line. I want krop to change the pdf as little as possible and only crop the margins.

I realized, that by default krop is using the Optimize PDF option via ghostscript, which I think compresses the images and even tries to replace fonts if they are not available in the system. This is something I would like to avoid

I suggest adding a command-line option --gs-optimize that would be False by default, so one could use e.g.

krop --go --autotrim --gs-optimize --output fout.pdf fin.pdf

Issues with snap+gs, pdftk

First: I like this app, thank you. But running in Kubuntu 20.04 (Focal):

The snap version of Krop does not see gs which is not a snap; the gs option is grayed out.

Krop fails - crashes - with Could not find object when used on a page that was excerpted from a multi-page PDF with pdftk, as in e.g. pdftk in.pdf cat 35 out.pdf.

Anyway, I installed Krop directly from Github and now it does all I want it to do, which is cutting out individual articles from NASA Tech Briefs, producing small output files. Except now I won't know when and how to upgrade to a new version.

Transparent background

Hello @arminstraub,

Thank you for the great software!

I remember that krop used to have a feature that that could display the pages in transparent mode (it was around 10 years ago), but in the current version I couldn't find that option anymore. Is it hidden somewhere?

Thanks in advance for your reply.

Selections apply settings doesn't show up.

In the screenshot there is a section in the gui in the basic tab to apply selections to all pages, even/odd pages, or individual pages and include exceptions. I don't see that in krop-0.5.1-10 in Fedora 34. A selection has been created yet the aforementioned area doesn't show up.
kropimpotent
as opposed to
image

Asking permission to publish krop on flathub

Hi Armin,

Flathub is a build and distribution platform for Linux apps, packaged in
a way that makes them portable and running on all major distributions.
Anyone can submit an app (we're not doing it for profit), but one of the
requirements is to reach out to the application's authors if they would
like to help with maintenance and thus making that distribution channel
considered official.

I'm volunteering to make a flatpak for krop to be published in https://flathub.org/.

The usual maintenance for new releases is just changing version string and
the file checksum. The rest is done by flathub's build infraestructure.

It's understandable if you can't commit to maintaining it, I can do the new
version updates as I'm the original packager and interested in having
krop on flathub, but we'd like to know if you are not against
distributing it on Flathub in general
.

Thank you,
Nelson

port snap app upstream

Hi @arminstraub,

I think it would be a good idea to port the snap config files and snap creation to this repo...
e.g. a push to this repo would trigger a new candidate version of the snap app...

what do you think? I did not update the snap app for a while, most changes that I made were throughing qt4 away...

Steps to port snap krop to this repo:

  • ask in https://forum.snapcraft.io to transfer snap app rights to you -> I can ask
  • port the snapcraft yaml files to thsi repo -> me
  • update text on software center
  • push new version

Let me know what you think 🔥

Flathub support

To push the popularity of this app and simplify the installation you could publish it on Flathub as a Flatpak.

BTW, I would totally love to see the following features from your ToDo list soon:

Automatize splitting pages in common ways (for instance, one page into two equally sized pages)
Specify aspect ratio of crop regions
Clone regions (and keep them linked)

Many thanks for the work you've already done!

--autotrim individual pages

Hi,

Is it possible to have --autotrim either automatically generate a "Trim margins" crop box for each individual page, or compute the largest crop box for the full page range? I have some very long (>1000 pages) documents I'd like to make more readable on a small screen e-reader, and i'd rather not check each crop box individually :)

Thanks!

PyPDF2 usage: New syntax / deprecations and the dependency

Hi!

I've noticed that krop uses PyPDF2. Is there a reason for not putting it in the setup.py as a dependency?

PyPDF2 has changed a lot since April. We try hard not to break stuff (see deprecation process), but we also want to move forward. As we modernized the API, a lot of the names changed. It's mostly switching from camelCase to snake_case, but see CHANGELOG "deprecation" for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.