Table of Contents

Method RenderPageAsync

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

RenderPageAsync(string, int, PdfRenderOptions, CancellationToken)

Renders a single PDF page as an ImageBuffer.

public static Task<ImageBuffer> RenderPageAsync(string inputPath, int pageIndex, PdfRenderOptions options = null, CancellationToken cancellationToken = default)

Parameters

inputPath string

Path to the source PDF.

pageIndex int

Zero-based index of the page to render.

options PdfRenderOptions

Render options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.

cancellationToken CancellationToken

Cancels the operation.

Returns

Task<ImageBuffer>

Examples

using LMKit.Document.Pdf;
using LMKit.Media.Image;

PdfRenderOptions options = new() { Zoom = 2.0, PixelFormat = ImagePixelFormat.RGB24 };
using ImageBuffer page = PdfRenderer.RenderPage("report.pdf", pageIndex: 0, options);
page.SaveAsPng("page-1.png");
Console.WriteLine($"Rendered {page.Width}x{page.Height} pixels.");

RenderPageAsync(Stream, int, PdfRenderOptions, bool, CancellationToken)

Renders a single PDF page as an ImageBuffer.

public static Task<ImageBuffer> RenderPageAsync(Stream input, int pageIndex, PdfRenderOptions options = null, bool leaveOpen = true, CancellationToken cancellationToken = default)

Parameters

input Stream

Readable stream containing the PDF.

pageIndex int

Zero-based index of the page to render.

options PdfRenderOptions

Render options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.

leaveOpen bool

When true (default), the caller keeps ownership of the stream.

cancellationToken CancellationToken

Cancels the operation.

Returns

Task<ImageBuffer>

Examples

using System.IO;
using LMKit.Document.Pdf;
using LMKit.Media.Image;

// Render a page directly from an HTTP response or blob stream
using FileStream pdfStream = File.OpenRead("report.pdf");
using ImageBuffer page = PdfRenderer.RenderPage(pdfStream, pageIndex: 0);
page.SaveAsJpeg("page-1.jpg", quality: 90);

RenderPageAsync(byte[], int, PdfRenderOptions, CancellationToken)

Renders a single PDF page as an ImageBuffer.

public static Task<ImageBuffer> RenderPageAsync(byte[] data, int pageIndex, PdfRenderOptions options = null, CancellationToken cancellationToken = default)

Parameters

data byte[]

PDF file content as a byte array.

pageIndex int

Zero-based index of the page to render.

options PdfRenderOptions

Render options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.

cancellationToken CancellationToken

Cancels the operation.

Returns

Task<ImageBuffer>

Examples

using System.IO;
using LMKit.Document.Pdf;
using LMKit.Media.Image;

byte[] bytes = File.ReadAllBytes("report.pdf");
using ImageBuffer page = PdfRenderer.RenderPage(bytes, pageIndex: 0);
page.SaveAsPng("page-1.png");
Share