Skip to content

Generated single page PDF is huge #3012

Answered by pubpub-zz
Vafilor asked this question in Q&A
Discussion options

You must be logged in to vote

this PDF is an example of files where the ressources shared between all the pages.

the full /Resources is shared between all pages, so cleaning should be done carefully.
considering a case where many pages could be added, this is a (draft) proposal for clean up;

from pypdf import PdfReader, PdfWriter
from pathlib import Path
from io import BytesIO

# Assumes the downloaded PDF is in the same directory as this script
# Change if needed
reader = PdfReader("./live12-manual-en.pdf")
writer = PdfWriter()

writer.add_page(reader.pages[0])
writer.add_page(reader.pages[26])  # to get pages with some images
writer.add_page(reader.pages[28]) # to get pages with some images

used_obj = []
for p in …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@stefan6419846
Comment options

@Vafilor
Comment options

Answer selected by Vafilor
Comment options

You must be logged in to vote
1 reply
@Vafilor
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3011 on December 19, 2024 19:05.