Skip to content
Discussion options

You must be logged in to vote

As pypdf is written, this will only work for filters which are image-only and thus do not rely on external libraries like Pillow or jbig2dec.

If you do not care about using internal APIs, something like this works:

from pypdf import PdfWriter
from pypdf.generic import DecodedStreamObject, EncodedStreamObject


writer = PdfWriter(clone_from="resources/crazyones.pdf")
for index, obj in enumerate(writer._objects):
    if not isinstance(obj, EncodedStreamObject):
        continue
    new_stream = DecodedStreamObject()
    new_stream.set_data(obj.get_data())
    for key, value in dict(obj).items():
        if key not in {"/Filter"}:
            new_stream[key] = value
    writer._objects[index] =

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@j-t-1
Comment options

@stefan6419846
Comment options

Answer selected by j-t-1
Comment options

You must be logged in to vote
1 reply
@stefan6419846
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants