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

Can you add something to reduce the file size #115

Open
eelalzep opened this issue Apr 8, 2024 · 0 comments
Open

Can you add something to reduce the file size #115

eelalzep opened this issue Apr 8, 2024 · 0 comments

Comments

@eelalzep
Copy link

eelalzep commented Apr 8, 2024

`def compress_content_streams(self, level: int = -1) -> None:
"""
Compress the size of this page by joining all content streams and
applying a FlateDecode filter.

    However, it is possible that this function will perform no action if
    content stream compression becomes "automatic".
    """
    content = self.get_contents()
    if content is not None:
        content_obj = content.flate_encode(level)
        try:
            content.indirect_reference.pdf._objects[  # type: ignore
                content.indirect_reference.idnum - 1  # type: ignore
            ] = content_obj
        except AttributeError:
            if self.indirect_reference is not None and hasattr(
                self.indirect_reference.pdf, "_add_object"
            ):
                self.replace_contents(content_obj)
            else:
                raise ValueError("Page must be part of a PdfWriter")`
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

No branches or pull requests

1 participant