-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
PdfWriterThe PdfWriter component is affectedThe PdfWriter component is affectedis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Description
I'm just reducing the size of pdfs.
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.35
$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==5.4.0, crypt_provider=('cryptography', '43.0.3'), PIL=10.4.0Code + PDF
This is a minimal, complete example that shows the issue:
writer = PdfWriter(
clone_from=input_path,
)
writer.remove_images()
writer.compress_identical_objects(remove_identicals=True, remove_orphans=True)Share here the PDF file(s) that cause the issue. The smaller they are, the
better. Let us know if we may add them to our tests!
I think likely any pdf with an image. I grabbed one of pypdf's test pdfs and replicated:
AutoCad_Diagram.pdf
Traceback
This is the complete traceback I see:
Traceback (most recent call last):
File "/home/python/t2.py", line 306, in <module>
compress_file_with_pypdf(input_file, output_file)
File "/home/python/t2.py", line 26, in compress_file_with_pypdf
writer.compress_identical_objects(remove_identicals=True, remove_orphans=True)
File "/home/python/.venv/lib/python3.11/site-packages/pypdf/_writer.py", line 1657, in compress_identical_objects
assert isinstance(obj.indirect_reference, IndirectObject)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NullObject' object has no attribute 'indirect_reference'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
PdfWriterThe PdfWriter component is affectedThe PdfWriter component is affectedis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF