PageRange 类

class pypdf.PageRange(arg: slice | PageRange | str)[源代码]

基类: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).

static valid(input: Any) bool[源代码]

True if input is a valid initializer for a PageRange.

参数:

input -- A possible PageRange string or a PageRange object.

返回:

True, if the input is a valid PageRange.

to_slice() slice[源代码]

Return the slice equivalent of this page range.

indices(n: int) Tuple[int, int, int][源代码]

Assuming a sequence of length n, calculate the start and stop indices, and the stride length of the PageRange.

See help(slice.indices).

参数:

n -- the length of the list of pages to choose from.

返回:

Arguments for range().