abarker / pdfCropMargins

pdfCropMargins -- a program to crop the margins of PDF files
Other
349 stars 32 forks source link

Doesn't work with PyPDF2 3.0.0 #45

Closed dennevi closed 1 year ago

dennevi commented 1 year ago

When I installed pdfCropMargins a few days ago, it installed PyPDF2 3.0.0 for me.

The "-p" argument does absolutely nothing when using PyPDF2 3.0.0. I've tried to figure out why it doesn't work, but I cannot figure it out. One strange thing is that "-ap" argument still works with 3.0.0. I.e. "pdfCropMargins -ap 100 -p 0 document1.pdf" crops 100 pixels from each side of the document, but leaves a lot of white space around the small object that is in the middle of the document I'm using for testing.

When using "-v", it looks like the cropbox is calculated correctly, it just isn't applied to the pdf.

I tried downgrading PyPDF2 to 2.12.1, it works correctly.

I got these versions:

$ python --version
Python 3.10.3
$ pip install pdfcropmargins
Collecting pdfcropmargins
  Using cached pdfCropMargins-1.1.8-py2.py3-none-any.whl (1.8 MB)
Collecting PyPDF2>=2.11.0
  Using cached pypdf2-3.0.0-py3-none-any.whl (232 kB)
Collecting pillow>=9.3.0
  Downloading Pillow-9.3.0-cp310-cp310-win_amd64.whl (2.5 MB)
     ---------------------------------------- 2.5/2.5 MB 9.2 MB/s eta 0:00:00
Collecting wheel
  Downloading wheel-0.38.4-py3-none-any.whl (36 kB)
Collecting PySimpleGUI>=4.40.0
  Using cached PySimpleGUI-4.60.4-py3-none-any.whl (509 kB)
Collecting PyMuPDF>=1.20.0
  Downloading PyMuPDF-1.21.1-cp310-cp310-win_amd64.whl (11.7 MB)
     ---------------------------------------- 11.7/11.7 MB 11.1 MB/s eta 0:00:00
Installing collected packages: PySimpleGUI, wheel, PyPDF2, PyMuPDF, pillow, pdfcropmargins
  Attempting uninstall: pillow
    Found existing installation: Pillow 9.2.0
    Uninstalling Pillow-9.2.0:
      Successfully uninstalled Pillow-9.2.0
Successfully installed PyMuPDF-1.21.1 PyPDF2-3.0.0 PySimpleGUI-4.60.4 pdfcropmargins-1.1.8 pillow-9.3.0 wheel-0.38.4

[notice] A new release of pip available: 22.1.2 -> 22.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

Downgrading solves the issue:

$ pip uninstall PyPDF2
Found existing installation: PyPDF2 3.0.0
Uninstalling PyPDF2-3.0.0:
  Would remove:
    c:\users\denne\appdata\local\programs\python\python310\lib\site-packages\pypdf2-3.0.0.dist-info\*
    c:\users\denne\appdata\local\programs\python\python310\lib\site-packages\pypdf2\*
Proceed (Y/n)?
  Successfully uninstalled PyPDF2-3.0.0

$ pip install --user install pypdf2==2.12.1
Collecting install
  Downloading install-1.3.5-py3-none-any.whl (3.2 kB)
Collecting pypdf2==2.12.1
  Downloading pypdf2-2.12.1-py3-none-any.whl (222 kB)
     ---------------------------------------- 222.8/222.8 kB 6.9 MB/s eta 0:00:00
Installing collected packages: pypdf2, install
Successfully installed install-1.3.5 pypdf2-2.12.1

[notice] A new release of pip available: 22.1.2 -> 22.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
abarker commented 1 year ago

Thanks for the bug report. I'm getting the same errors. I pushed out version 1.1.9 of pdfCropMargins which requires PyPDF2 < 3.0.0 in setup.py. They've been making a lot of changes to that project recently, including a planned renaming to pypdf.

dennevi commented 1 year ago

Thank you for releasing a quick workaround! And thank you for a great tool! Just found it a few days ago, it will come in handy.

abarker commented 1 year ago

The new version 2.0.0 is now out. It removes the PyPDF dependency altogether and PyMuPDF is used for all internal calculations.