Skip to content

PageRange is not working #2545

Answered by stefan6419846
dtm00777 asked this question in Q&A
Discussion options

You must be logged in to vote

I do not know when or how your code has ever worked, but your PageRange usage is wrong as well. You should really have a look at our docs before trying to implement something as you imagine it could work.

Some possible solution might look like this:

import base64
from pypdf import PageRange, PdfReader, PdfWriter
from io import BytesIO



def split_pdf(reader, num_pages=16):
    try:      
        total_pages = len(reader.pages)
        print("total_pages:", total_pages)

        pages_per_chunk = total_pages // num_pages

        for i in range(num_pages):
            print("Page number is", i)
            start_page = i * pages_per_chunk
            end_page = (i + 1) * pages_per_chunk

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by stefan6419846
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 #2541 on March 26, 2024 13:47.