Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: '/T' #2078

Closed
the-superpirate opened this issue Aug 10, 2023 · 4 comments · Fixed by #2080
Closed

KeyError: '/T' #2078

the-superpirate opened this issue Aug 10, 2023 · 4 comments · Fixed by #2080
Labels
key-error Could be a bug, but also a robustness issue

Comments

@the-superpirate
Copy link

the-superpirate commented Aug 10, 2023

Traceback

This is the complete Traceback I see:

  File "main.py", line 247, in process
    pdf_writer.append(pdf_reader, [page_num])
  File "venv/lib/python3.10/site-packages/pypdf/_writer.py", line 2804, in append
    self.merge(
  File "venv/lib/python3.10/site-packages/pypdf/_utils.py", line 466, in wrapper
    return func(*args, **kwargs)
  File "venv/lib/python3.10/site-packages/pypdf/_writer.py", line 3001, in merge
    self.add_filtered_articles("", srcpages, reader)
  File "venv/lib/python3.10/site-packages/pypdf/_writer.py", line 3088, in add_filtered_articles
    thr = a.get_object()["/T"]
  File "venv/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 320, in __getitem__
    return dict.__getitem__(self, key).get_object()
KeyError: '/T'
@pubpub-zz
Copy link
Collaborator

Please provide version, simple code, and PDF. withouth these data we will have to close the issue as non reproductable

@pubpub-zz pubpub-zz added needs-test A test should be added before this PR is merged. needs-pdf The issue needs a PDF file to show the problem needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem and removed needs-test A test should be added before this PR is merged. labels Aug 10, 2023
@the-superpirate
Copy link
Author

pypdf==3.15.0
Code is the most simplest possible ever, something like

    def process(self, pdf_reader, pdf_writer):
        for page_num, page in enumerate(pdf_reader.pages):
            pdf_writer.append(pdf_reader, [page_num])

Unforunately PDF cannot be shared, it is private.

@the-superpirate
Copy link
Author

the-superpirate commented Aug 10, 2023

Ok, actually there is a lot of such files, this one can be shared:

import pypdf
pdf = pypdf.PdfReader('bad.pdf')
w = pypdf.PdfWriter()
for n in range(len(pdf.pages)):
    w.append(pdf, [n])

bad.pdf

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue Aug 10, 2023
@pubpub-zz pubpub-zz removed needs-pdf The issue needs a PDF file to show the problem needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem labels Aug 10, 2023
@pubpub-zz
Copy link
Collaborator

This PR should be good

MartinThoma pushed a commit that referenced this issue Aug 12, 2023
@MartinThoma MartinThoma added the key-error Could be a bug, but also a robustness issue label Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
key-error Could be a bug, but also a robustness issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants