Table of Contents

Method ExtractPages

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

ExtractPages(Attachment, string)

Extracts the specified pages from a PDF attachment and returns a new attachment containing only those pages.

public static Attachment ExtractPages(Attachment source, string pageRange)

Parameters

source Attachment

The source PDF attachment.

pageRange string

A 1-based page range string (e.g., "1-5, 7, 9-12"). Null, empty, or "*" extracts all pages.

Returns

Attachment

A new Attachment containing the extracted pages.

Examples

using System;
using LMKit.Data;
using LMKit.Document;

// Load a multi-page PDF
var source = new Attachment("contract.pdf");
Console.WriteLine($"Source has {source.PageCount} pages");

// Extract pages 2 through 4
Attachment extracted = PdfSplitter.ExtractPages(source, "2-4");
Console.WriteLine($"Extracted PDF has {extracted.PageCount} pages");

Exceptions

ArgumentNullException

Thrown when source is null.

ArgumentException

Thrown when the source attachment is not a PDF or when the page range resolves to zero pages.

ExtractPages(Attachment, int[])

Extracts the specified pages from a PDF attachment and returns a new attachment containing only those pages.

public static Attachment ExtractPages(Attachment source, int[] pageIndexes)

Parameters

source Attachment

The source PDF attachment.

pageIndexes int[]

Zero-based page indexes to extract.

Returns

Attachment

A new Attachment containing the extracted pages.

Examples

using System;
using LMKit.Data;
using LMKit.Document;

// Load a PDF
var source = new Attachment("report.pdf");

// Extract the first, third, and fifth pages (zero-based indexes)
Attachment extracted = PdfSplitter.ExtractPages(source, new[] { 0, 2, 4 });
Console.WriteLine($"Extracted PDF has {extracted.PageCount} pages");

Exceptions

ArgumentNullException

Thrown when source or pageIndexes is null.

ArgumentException

Thrown when the source attachment is not a PDF or when no page indexes are provided.

ExtractPages(string, string, string)

Extracts the specified pages from a PDF file and writes the result to an output file.

public static void ExtractPages(string inputPath, string pageRange, string outputPath)

Parameters

inputPath string

Path to the source PDF file.

pageRange string

A 1-based page range string (e.g., "1-5, 7, 9-12"). Null, empty, or "*" extracts all pages.

outputPath string

Path where the extracted PDF will be written.

Examples

using LMKit.Document;

// Extract the first 5 pages into a separate file
PdfSplitter.ExtractPages(
    "full_report.pdf",
    "1-5",
    "summary_pages.pdf");

// Extract non-contiguous pages (cover, TOC, and last page)
PdfSplitter.ExtractPages(
    "full_report.pdf",
    "1, 3, 50",
    "selected_pages.pdf");

Exceptions

ArgumentNullException

Thrown when inputPath or outputPath is null.

FileNotFoundException

Thrown when inputPath does not exist.

ExtractPages(string, int[], string)

Extracts the specified pages from a PDF file and writes the result to an output file.

public static void ExtractPages(string inputPath, int[] pageIndexes, string outputPath)

Parameters

inputPath string

Path to the source PDF file.

pageIndexes int[]

Zero-based page indexes to extract.

outputPath string

Path where the extracted PDF will be written.

Examples

using LMKit.Document;

// Extract pages by zero-based indexes
PdfSplitter.ExtractPages(
    "full_report.pdf",
    new[] { 0, 4, 9 },
    "selected_pages.pdf");

Exceptions

ArgumentNullException

Thrown when inputPath or outputPath is null.

FileNotFoundException

Thrown when inputPath does not exist.