The PageRange Class

class PyPDF2.PageRange(arg)[source]

Bases: object

A slice-like representation of a range of page indices.

For example, page numbers, only starting at zero.

The syntax is like what you would put between brackets [ ]. The slice is one of the few Python types that can’t be subclassed, but this class converts to and from slices, and allows similar use.

  • PageRange(str) parses a string representing a page range.

  • PageRange(slice) directly “imports” a slice.

  • to_slice() gives the equivalent slice.

  • str() and repr() allow printing.

  • indices(n) is like slice.indices(n).


n is the length of the list of pages to choose from. Returns arguments for range(). See help(slice.indices).


Return the slice equivalent of this page range.

static valid(input)[source]

True if input is a valid initializer for a PageRange.