Skip to content

KeyError: '/Info' #2049

@mnmtz

Description

@mnmtz

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.0

Code + 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 += 1

example_024.pdf

Traceback

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFkey-errorCould be a bug, but also a robustness issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions