Table of Contents

Method SavePagesAsPngsAsync

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

SavePagesAsPngsAsync(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)

Renders the selected pages and writes one PNG per page.

public static Task<IReadOnlyList<string>> SavePagesAsPngsAsync(string inputPath, string outputDirectory, PdfRenderOptions options = null, int compressionLevel = 6, string fileNamePrefix = "page", IProgress<PdfRenderProgressEventArgs> progress = null, CancellationToken cancellationToken = default)

Parameters

inputPath string

Path to the source PDF.

outputDirectory string

Folder to write the per-page output files into. Created if missing.

options PdfRenderOptions

Render options including PageRange.

compressionLevel int

PNG compression level 0-9. Default 6.

fileNamePrefix string

Prefix for each output filename. Files are named {prefix}-{1-based page}.png.

progress IProgress<PdfRenderProgressEventArgs>

Optional progress callback fired after each saved page.

cancellationToken CancellationToken

Cancels the operation between pages.

Returns

Task<IReadOnlyList<string>>

Examples

using System;
using LMKit.Document.Pdf;

PdfRenderOptions options = new() { Zoom = 2.0, PageRange = "1-10" };
Progress<PdfRenderProgressEventArgs> progress = new(e =>
    Console.WriteLine($"Saved page {e.PageIndex + 1} / {e.TotalPages} -> {e.OutputPath}"));

IReadOnlyList<string> files = PdfRenderer.SavePagesAsPngs(
    "report.pdf", outputDirectory: "thumbs", options,
    compressionLevel: 6, fileNamePrefix: "thumb", progress);
Share