Skip to content

KeyError: '/Resources' #1272

@DL6ER

Description

@DL6ER

See #1269 for further details.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.4.0-122-generic-x86_64-with-glibc2.29

$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.10.3

Code + PDF

This is a minimal, complete example that shows the issue:

from PyPDF2 import PdfReader
with open("TelemetryTX_EM.pdf", "rb") as f:
    reader = PdfReader(f, strict=False)
    full_content = " ".join([page.extract_text() for page in reader.pages])

PDF used above: main.pdf

Traceback

This is the complete Traceback I see:

Traceback (most recent call last):
  File "test4.py", line 4, in <module>
    content = " ".join([page.extract_text() for page in reader.pages])
  File "test4.py", line 4, in <listcomp>
    content = " ".join([page.extract_text() for page in reader.pages])
  File "/usr/local/lib/python3.8/dist-packages/PyPDF2/_page.py", line 1510, in extract_text
    return self._extract_text(
  File "/usr/local/lib/python3.8/dist-packages/PyPDF2/_page.py", line 1143, in _extract_text
    resources_dict = cast(DictionaryObject, obj["/Resources"])
  File "/usr/local/lib/python3.8/dist-packages/PyPDF2/generic/_data_structures.py", line 150, in __getitem__
    return dict.__getitem__(self, key).get_object()
KeyError: '/Resources'

Metadata

Metadata

Assignees

No one assigned

    Labels

    key-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