arminstraub / krop

A simple graphical tool to crop the pages of PDF files, written in Python/Qt
http://arminstraub.com/software/krop
GNU General Public License v3.0
116 stars 16 forks source link

error has occured: file has not been decrypted #19

Closed garywill closed 4 years ago

garywill commented 5 years ago

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

suuuehgi commented 4 years ago

For a workaround, you might use beforehand:

qpdf --password='' --decrypt fx_82TL_350TL.pdf fx_82TL_350TL_decrypted.pdf
arminstraub commented 4 years ago

Thank you both! The next version of krop will automatically decrypt (some) PDFs with an empty password. If that fails, the suggestion to use qpdf first will be displayed. The code is already on github in case you want to give it a try. Please forgive the terrible delay!