-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f01f77
commit 724a902
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Reduce PDF Size | ||
|
||
There are multiple ways to reduce the size of a given PDF file. The easiest | ||
one is to remove content (e.g. images) or pages. | ||
|
||
## Remove images | ||
|
||
|
||
```python | ||
import PyPDF2 | ||
|
||
reader = PyPDF2.PdfFileReader("example.pdf") | ||
writer = PyPDF2.PdfFileWriter() | ||
|
||
for page in reader.pages: | ||
writer.addPage(page) | ||
|
||
writer.removeImages() | ||
|
||
with open("out.pdf", "wb") as f: | ||
writer.write(f) | ||
``` | ||
|
||
## Compression | ||
|
||
```python | ||
import PyPDF2 | ||
|
||
reader = PyPDF2.PdfFileReader("example.pdf") | ||
writer = PyPDF2.PdfFileWriter() | ||
|
||
for page in reader.pages: | ||
page.compressContentStreams() | ||
writer.addPage(page) | ||
|
||
with open("out.pdf", "wb") as f: | ||
writer.write(f) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters