Skip to content

PageRange

PageRange is the immutable implementation of IPageRange, and its static Parse method converts a comma-separated page-expression string (e.g., "1-5,7,9-*,*") into an array of ranges — the mechanism behind Parse a page expression. It carries a [JsonConstructor] companion constructor so it can round-trip through serialization.

Purpose

  • Represents one contiguous or single-page selection with computed classification flags (IsPartial, IsOriginal, IsSingle).
  • Parses a page-expression string into an array of PageRange values, silently skipping tokens that do not match the grammar. (BR-25, BR-26)
  • Renders a range back to its expression form via ToString().

Context

  • Namespace: PdfAPI.Core
  • Assembly/package: PdfAPI.Core

Public members

Member Signature Purpose
PageRange(int, int) PageRange(int start, int stop) Constructs an explicit start/stop range.
PageRange(int, bool) PageRange(int start, bool isSinglePage = true) Constructs a single-page range, or an open-ended range starting at start when isSinglePage is false.
PageRange() PageRange() Parameterless constructor used for JSON deserialization.
StartPage int StartPage { get; } The first page (1-based) included in the selection.
StopPage int StopPage { get; } The last page included in the selection; -1 denotes open-ended. (BR-15)
IsPartial bool IsPartial { get; } Indicates the selection covers a subset of pages.
IsOriginal bool IsOriginal { get; } Indicates the selection spans the entire original document. (BR-14)
IsSingle bool IsSingle { get; } Indicates the selection covers exactly one page.
Parse(string) static PageRange[] Parse(string text) Splits a comma-separated expression into tokens and converts each recognised token into a PageRange, skipping tokens that do not match. (BR-25, BR-26, BR-27, BR-28, BR-29)
ToString() override string ToString() Renders the range back into its page-expression textual form.

Behavioral notes

  • A stop page of zero or less in a start-stop token is normalised to -1 (open-ended) during parsing. (BR-27)
  • A bare * token produces an all-pages range (1 to -1). (BR-28)

Constraints and usage notes

  • Parse never throws on malformed input; it simply omits unmatched tokens from the result, which can silently yield an empty array. (BR-26)

Sources

  • PdfAPI.Core\Extract\PageRange.cs