Skip to content

Commit f20c36e

Browse files
authored
Improve lossless compression example (#2488)
Simplify the previous version and remove the side effect of changing the PDF in ways not just related to lossless compression (e.g. links on content page did not work in the created PDF).
1 parent afbee38 commit f20c36e

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

docs/user/file-size.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,11 @@ Deflate compression can be applied to a page via
8181
[`page.compress_content_streams`](https://pypdf.readthedocs.io/en/latest/modules/PageObject.html#pypdf._page.PageObject.compress_content_streams):
8282

8383
```python
84-
from pypdf import PdfReader, PdfWriter
85-
86-
reader = PdfReader("example.pdf")
87-
writer = PdfWriter()
84+
from pypdf import PdfWriter
8885

89-
for page in reader.pages:
90-
writer.add_page(page)
86+
writer = PdfWriter(clone_from="example.pdf")
9187

9288
for page in writer.pages:
93-
# ⚠️ This has to be done on the writer, not the reader!
9489
page.compress_content_streams() # This is CPU intensive!
9590

9691
with open("out.pdf", "wb") as f:

0 commit comments

Comments
 (0)