Table of Contents

Class PageRange

Namespace
LMKit.Document
Assembly
LM-Kit.NET.dll

Provides utility methods for parsing page range strings into zero-based page indexes.

public static class PageRange
Inheritance
PageRange
Inherited Members

Examples

Example 1: Parse various page range formats.

using LMKit.Document;

int totalPages = 20;

// Single page (returns [2] because "3" is 1-based, converted to 0-based). List<int> single = PageRange.GetPageIndexes("3", totalPages);

// Range of pages (returns [0, 1, 2, 3, 4]). List<int> range = PageRange.GetPageIndexes("1-5", totalPages);

// Comma-separated mix (returns [0, 1, 2, 3, 4, 6, 8, 9, 10, 11]). List<int> mixed = PageRange.GetPageIndexes("1-5, 7, 9-12", totalPages);

// All pages (returns [0..19]). List<int> all = PageRange.GetPageIndexes(null, totalPages); List<int> allStar = PageRange.GetPageIndexes("*", totalPages);

Example 2: Use with an Attachment.

using LMKit.Data;
using LMKit.Document;

var attachment = new Attachment("report.pdf"); List<int> pages = PageRange.GetPageIndexes(attachment, "1-3, 10");

Console.WriteLine($"Processing pages: {string.Join(", ", pages)}");

Remarks

Page range strings use 1-based page numbers and support the following formats:

  • Single pages: "3", "7"
  • Ranges: "1-5", "10-15"
  • Comma-separated combinations: "1-5, 7, 9-12"
  • Reversed ranges (normalized automatically): "5-1"
  • All pages: null, "", or "*"

Out-of-range page numbers are silently ignored. Duplicate indexes are deduplicated. Results are always returned sorted in ascending order.

Methods

GetPageIndexes(Attachment, string)

Parses a page range string and returns a sorted list of zero-based page indexes valid for the specified Attachment.

GetPageIndexes(string, int)

Parses a page range string and returns a sorted list of zero-based page indexes.

Share