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

Some images in pdf can not be removed using 'remove_images()' #2103

Closed
animebing opened this issue Aug 21, 2023 · 4 comments · Fixed by #2133
Closed

Some images in pdf can not be removed using 'remove_images()' #2103

animebing opened this issue Aug 21, 2023 · 4 comments · Fixed by #2133

Comments

@animebing
Copy link

Some images in pdf can not be removed using the method metioned here. There is only one page in the pdf and the output of 'len(page.images)' is 32, When I do 'remove_images()', they are still in the new created pdf.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
# Windows-10-10.0.22621-SP0

$ python -c "import pypdf;print(pypdf.__version__)"
# 3.15.2

Code + PDF

This is a minimal, complete example that shows the issue:

import os
import sys

from pypdf import PdfReader, PdfWriter


src_pdf_path = sys.argv[1]
dst_pdf_path = os.path.splitext(src_pdf_path)[0] + '_no_images.pdf'

reader = PdfReader(src_pdf_path)
writer = PdfWriter()

for page in reader.pages:
    writer.add_page(page)

writer.remove_images()
with open(dst_pdf_path, "wb") as f:
    writer.write(f)

2210.03142-1.pdf

@pubpub-zz
Copy link
Collaborator

the images are in a XObject/Form within an XObject/Form
I've modified the code to cope with such situations for all remove_xxx functions

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue Aug 30, 2023
MartinThoma pushed a commit that referenced this issue Aug 31, 2023
Some images could not be removed using remove_images. There is only one page in the pdf and the output of 'len(page.images)' was 32, even after 'remove_images()'.

The reason was that images are in a XObject/Form within an XObject/Form.
This commit modifies the code to cope with such situations for all remove_xxx functions.

Closes #2103
@MartinThoma
Copy link
Member

The bugfix by @pubpub-zz was just merged and will be released on 3rd of September in pypdf > 3.15.4

@MartinThoma
Copy link
Member

@animebing Thank you for reporting the issue 🙏 If you want, I can add you to https://pypdf.readthedocs.io/en/latest/meta/CONTRIBUTORS.html

@animebing
Copy link
Author

@MartinThoma Thanks for solving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants