-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
is-featureA feature requestA feature request
Description
Explanation
PDF file size matters, especially if you need to send documents via e-mail or for people with bad internet. Smaller file sizes make handling the document easier.
Evidence that people care about this topic:
- Optimize PDF files
- How can I lossless reduce PDF file size?
- How can I reduce the file size of PDF files in C#?
What this is NOT about:
- Image size reductions done by the user: We describe that in https://pypdf.readthedocs.io/en/latest/user/file-size.html#removing-images .In the context of this enhancement proposal, we can also look at image formats / possibilities for size reduction, but it should require little user knowledge. For example, I could imagine that we automatically apply better compression algorithms.
Goals
- Simpler file size reduction for users
- Better reduction
Code Example
Similar to what we have already:
from pypdf import PdfReader, PdfWriter
reader = PdfReader("example.pdf")
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
# That is the new thing:
# - some flag to indicate if lossy / lossless compression is desired
# - maybe a flag that steers CPU usage? Sometimes compression is rather time-intensive
writer.compress(image_quality=85)
with open("out.pdf", "wb") as f:
writer.write(f)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
is-featureA feature requestA feature request