Method RenderPageAsync
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
inputPathstringPath to the source PDF.
pageIndexintZero-based index of the page to render.
optionsPdfRenderOptionsRender options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.
cancellationTokenCancellationTokenCancels the operation.
Returns
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
inputStreamReadable stream containing the PDF.
pageIndexintZero-based index of the page to render.
optionsPdfRenderOptionsRender options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.
leaveOpenboolWhen true (default), the caller keeps ownership of the stream.
cancellationTokenCancellationTokenCancels the operation.
Returns
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
databyte[]PDF file content as a byte array.
pageIndexintZero-based index of the page to render.
optionsPdfRenderOptionsRender options (zoom, pixel format, orientation, annotations, password). PageRange is ignored.
cancellationTokenCancellationTokenCancels the operation.
Returns
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");