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

Getting KeyError: '/Kids' for getNumPages #500

Closed
bikashgupta11 opened this issue Apr 26, 2019 · 8 comments · Fixed by #1845
Closed

Getting KeyError: '/Kids' for getNumPages #500

bikashgupta11 opened this issue Apr 26, 2019 · 8 comments · Fixed by #1845
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF needs-pdf The issue needs a PDF file to show the problem

Comments

@bikashgupta11
Copy link

bikashgupta11 commented Apr 26, 2019

For a specific PDF, its giving error KeyError: '/Kids'

Code

from PyPDF2 import PdfFileReader

reader = PdfFileReader("example.pdf")
reader.getNumPages()

Traceback

Stacktrace
pageNum = src_pdf.getNumPages()
File "C:\Miniconda3\envs\1\lib\site-packages\PyPDF2\pdf.py", line 1155, in getNumPages
self._flatten()
File "C:\Miniconda3\envs\1\lib\site-packages\PyPDF2\pdf.py", line 1520, in _flatten
self._flatten(page.getObject(), inherit, **addt)
File "C:\Miniconda3\envs\1\lib\site-packages\PyPDF2\pdf.py", line 1516, in _flatten
for page in pages["/Kids"]:
File "C:\Miniconda3\envs\1\lib\site-packages\PyPDF2\generic.py", line 516, in getitem
return dict.getitem(self, key).getObject()
KeyError: '/Kids'

Document Info

image

@bikashgupta11
Copy link
Author

Analysis:-
IndirectObject of Kids has type "Pages" not "Page". Hence its recursively trying to flatten Pages however its not getting the Kids attribute. Also as it does not have "Page" object hence flattenPages length is not appended.

Now the PDF Version is 1.0(Acrobat 1.x). If I save the same PDF with different name then its version its getting change and its working.

image

image

@MartinThoma MartinThoma added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label Apr 7, 2022
@MartinThoma
Copy link
Member

I realize it's been a long time, but ... Do you happen to have the PDF that causes / caused those issues? Could you share it?

@MartinThoma MartinThoma added 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-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem labels Jun 28, 2022
@MartinThoma
Copy link
Member

As too much has changed since this was last encountered and there is no example PDF, I'll close this.

If anybody sees this issue again with a recent PyPDF2 version, please let me know!

@Ontheroad123
Copy link

As too much has changed since this was last encountered and there is no example PDF, I'll close this.

If anybody sees this issue again with a recent PyPDF2 version, please let me know!

I have meet 'KeyError: '/Kids'' error, PyPDF2=='3.0.1',
Taylor’s Differential Diagnosis Manual_ Symptoms and Signs in the Time-Limited Encounter.pdf

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue May 18, 2023
Fixes py-pdf#500
these PDF are not compliant with Standard (Type is mandatory in page tree nodes however Acrobat Reader can open them
Robustness improved
@pubpub-zz
Copy link
Collaborator

The PDF is not compliant with the Standard : /Type field is missing on the Pages Nodes and on the Page Objects. However the document can be opened by Acrobat Reader. Page objects are now considered also if /Contents is present (although not or if /Kids is not present

MartinThoma pushed a commit that referenced this issue May 20, 2023
/Type is mandatory in page tree nodes according to the the PDF specification. Hence dealing with such files is a robustness improvements.
Acrobat Reader can open such PDF documents as well.

Fixes #500
@MartinThoma
Copy link
Member

I've just merged the fix by @pubpub-zz (thank you again 🤗 )

The fix will be part of pypdf > 3.8.1.

@pachhaipurna
Copy link

@MartinThoma I am having this /Kids Type error in my pdf file, I tried to create a new pdf file based on Page number after updating some attributes, If I create individually it is working fine. But When I tried to combine multiple page at once, the Attributes are not updating.

@pubpub-zz
Copy link
Collaborator

@pachhaipurna
Please create a new issue with all data (version, code +pdf, error reported )
Like this we can not analyse the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF needs-pdf The issue needs a PDF file to show the problem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants