Created
November 5, 2024 04:56
-
-
Save oyiptong/19204dc07043ca4f0071e603ea3fa48b to your computer and use it in GitHub Desktop.
A program that splits a PDF document into multiple 15-page documents.
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
import sys | |
from PyPDF2 import PdfWriter, PdfReader | |
inputpdf = PdfReader(open("book_name.pdf", "rb")) | |
pages = list(range(0, len(inputpdf.pages))) | |
chunk_size = 15 | |
page_chunks = [pages[i:i + chunk_size] for i in range(0, len(inputpdf.pages), chunk_size)] | |
chunk_count = 0 | |
for chunk in page_chunks: | |
chunk_count += 1 | |
output = PdfWriter() | |
for page in chunk: | |
output.add_page(inputpdf.pages[page]) | |
with open("document-chunk-{:02d}.pdf".format(chunk_count), "wb") as outputStream: | |
output.write(outputStream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment