-
Notifications
You must be signed in to change notification settings - Fork 1.6k
KeyError: '/Info' #2049
Description
KeyError raised when reading PDF file. It seems that the file is missing the /Info key, but file is correctly displayed using Acrobat Reader, Chrome or qpdf. I could not find a clear definition in the PDF reference, but as far as I know, the /Info key is recommended, but not required in a PDF document.
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Windows-10-10.0.22621-SP0
$ python -c "import pypdf;print(pypdf.__version__)"
3.14.0Code + PDF
This is a minimal, complete example that shows the issue:
reader = PdfReader(file, strict=False)
writer = PdfWriter()
writer.clone_document_from_reader(reader)
for page in writer.pages:
for img_obj in page.images:
img_count += 1Traceback
This is the truncated Traceback I see:
File "C:\Users\-----\AppData\Local\Programs\Python\Python311\Lib\site-packages\pypdf_writer.py", line 1129, in clone_document_from_reader
self._info = reader.trailer[TK.INFO].clone(self).indirect_reference # type: ignore
~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Users\-----\AppData\Local\Programs\Python\Python311\Lib\site-packages\pypdf\generic_data_structures.py", line 320, in getitem
return dict.getitem(self, key).get_object()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '/Info'