-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I'm trying to merge a few PDF files using this library into one single file by just appending them into a new document one-by-one. However, some of the input files seem to run into the error described in the title above when trying to call append(fileobj=open(...)).
I suspect it has something to do with the image shown on the example PDF... it might not be "imported" properly or something, as it also disappears from the slide when trying to use the "Black"-Feature of Adobe Acrobat.
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Linux-5.15.79.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
$ python -c "import pypdf;print(pypdf.__version__)"
3.4.0Code + PDF
This is a minimal, complete example that shows the issue:
output_pdf_stream = PdfWriter()
output_pdf_stream.append(fileobj=open("broke.pdf", "rb"))Full example file
from pypdf import errors, PdfWriter
def main():
output_pdf_stream = PdfWriter()
output_pdf_stream.append(fileobj=open("broke.pdf", "rb"))
# does not reach here
# create output pdf file
try:
output_pdf_file = open("test.pdf", "wb")
output_pdf_stream.write(output_pdf_file)
finally:
output_pdf_file.close()
output_pdf_stream.close()
print("%s successfully created." % output_pdf_name)
if __name__ == "__main__":
main()I don't own the right to any of the contents on this slide, but I'm sure some of your magicians can craft up a similar file for the testing environments.
broke.pdf
Traceback
This is the complete Traceback I see:
Traceback (most recent call last):
File "/mnt/d/Eigene_Dateien/Downloads/Netzsicherheit 1 (212012-WiSe2223)/minimal.py", line 22, in <module>
main()
File "/mnt/d/Eigene_Dateien/Downloads/Netzsicherheit 1 (212012-WiSe2223)/minimal.py", line 5, in main
output_pdf_stream.append(fileobj=open("broke.pdf", "rb"))
File "/usr/local/lib/python3.10/dist-packages/pypdf/_writer.py", line 2476, in append
self.merge(
File "/usr/local/lib/python3.10/dist-packages/pypdf/_utils.py", line 441, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pypdf/_writer.py", line 2599, in merge
lst = self._insert_filtered_annotations(
File "/usr/local/lib/python3.10/dist-packages/pypdf/_writer.py", line 2768, in _insert_filtered_annotations
outlist.append(ano.clone(self).indirect_reference)
AttributeError: 'DictionaryObject' object has no attribute 'indirect_reference'