Replies: 5 comments
-
+1 |
Beta Was this translation helpful? Give feedback.
-
@Akaiame: This may be useful to you... In my project I was able to install
I believe it is converting the generated PDF into a 130-dpi image, compressing as Zip, and exporting back to PDF. Note that any rich PDF interactivity like highlighting text would be nixxed as it's now just a 130-dpi image. cheers.. |
Beta Was this translation helpful? Give feedback.
-
@pztrick: I'm already using imagemagick in my project, so I might have to give it a go. I was also considering using ghostscript to downsample after merging the pages, which seems to return the PDF back to its original size before the merge... Still it would be nice to have compression inside PyPDF2! Thanks for the suggestion! |
Beta Was this translation helpful? Give feedback.
-
Is there any news about this thread? |
Beta Was this translation helpful? Give feedback.
-
I'm open to add a compression parameter to def write(self, stream: StreamType, compress: Literal[None, "FLATE"]=None) -> None: Are there other compression methods supported by PDF? How do other libraries (PyMuPDF / pikepdf / pdfrw / ...) do it? As a side-note: https://pypdf2.readthedocs.io/en/latest/user/file-size.html |
Beta Was this translation helpful? Give feedback.
-
Hello,
There is a
PageObject.compressContentStreams
method that no longer seems to be referenced anywhere in the project.I believe this used to compress PDFs using Zip/Flate to result in a smaller file size.
https://github.com/mstamy2/PyPDF2/blob/8cbca8c8824bcf2ea2b18f9a56e2d7eee3b3fe96/PyPDF2/pdf.py#L2324
I tried invoking
page.compressContentStreams
directly before passing toPdfFileWriter
for outputing to a file stream but it did not seem to work.Could compression be added to the library? (Ideally as a keyword argument to
PdfFileWriter.write
?)Beta Was this translation helpful? Give feedback.
All reactions