-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Merging/watermarking a PDF file with another might raise a KeyError when retrieving the resources.
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Linux-5.14.21-150400.24.81-default-x86_64-with-glibc2.31
$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==3.15.5, crypt_provider=('pycryptodome', '3.18.0'), PIL=10.0.0Code + PDF
This is a minimal, complete example that shows the issue:
from pypdf import PdfReader, PdfWriter
watermark = PdfReader("watermark.pdf").pages[0]
pdf_file = PdfWriter(clone_from="file.pdf")
for page in pdf_file.pages:
page.merge_page(watermark, over=True)The watermark is https://github.com/py-pdf/pypdf/files/12428857/watermark.pdf I have not yet found a base document I can share for reproduction.
Traceback
This is the complete traceback I see:
Traceback (most recent call last):
File "/home/stefan/temp/run1.py", line 7, in <module>
page.merge_page(watermark, over=True)
File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 1044, in merge_page
self._merge_page(page2, over=over, expand=expand)
File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 1071, in _merge_page
return self._merge_page_writer(
File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 1182, in _merge_page_writer
original_resources = cast(DictionaryObject, self[PG.RESOURCES].get_object())
File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/generic/_data_structures.py", line 320, in __getitem__
return dict.__getitem__(self, key).get_object()
KeyError: '/Resources'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels