py-pdf / pypdf

A pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files
https://pypdf.readthedocs.io/en/latest/
Other
8.37k stars 1.41k forks source link

ValueError: key must be PdfObject #2316

Closed shafeeralip closed 11 months ago

shafeeralip commented 11 months ago

Hey, I'm pretty sure it's just because I'm doing something wrong

Traceback (most recent call last):
  File "/Users/shafeerali/Documents/Nanonets/avanto/API/ap2.py", line 196, in get_page_from_pdf
    image['/Resources']['/ProcSet'] = ['/PDF', '/Text', '/ImageB', '/ImageC', '/ImageI']
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyPDF2/generic/_data_structures.py", line 253, in __setitem__
    raise ValueError("key must be PdfObject")
ValueError: key must be PdfObject
input_pdf = PdfReader(dwnld_filepath)
output_pdf = PdfWriter()
image = input_pdf.pages[page_number]
image['/Resources']['/ProcSet'] = ['/PDF', '/Text', '/ImageB', '/ImageC', '/ImageI']
output_pdf.add_page(image)
stefan6419846 commented 11 months ago

PyPDF2 is deprecated and unsupported, please switch to pypdf.

Additionally, could you please elaborate on what you are trying to achieve? The issue itself seems to stem from the fact the keys probably should be NameObject instances.