MiniGlome / Archive.org-Downloader

Python3 script to download archive.org books in PDF format
896 stars 118 forks source link

Can you add something to reduce the file size #115

Open eelalzep opened 7 months ago

eelalzep commented 7 months ago

`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")`