Method SavePageAsPng
SavePageAsPng(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a file.
public static void SavePageAsPng(string inputPath, int pageIndex, string outputPath, PdfRenderOptions options = null, int compressionLevel = 6, CancellationToken cancellationToken = default)
Parameters
inputPathstringPath to the source PDF.
pageIndexintZero-based index of the page to render.
outputPathstringDestination file path.
optionsPdfRenderOptionsRender options. PageRange is ignored.
compressionLevelintPNG compression level
0(fastest) to9(smallest). Default6.cancellationTokenCancellationTokenCancels the operation.
Examples
using LMKit.Document.Pdf;
PdfRenderer.SavePageAsPng("report.pdf", pageIndex: 0, "thumb.png");
// Smallest PNG (slowest), grayscale, at 3x zoom
PdfRenderOptions options = new()
{
Zoom = 3.0,
PixelFormat = LMKit.Media.Image.ImagePixelFormat.GRAY8,
};
PdfRenderer.SavePageAsPng("scan.pdf", 0, "thumb.png", options, compressionLevel: 9);
SavePageAsPng(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a writable stream.
public static void SavePageAsPng(string inputPath, int pageIndex, Stream outputStream, PdfRenderOptions options = null, int compressionLevel = 6, CancellationToken cancellationToken = default)
Parameters
inputPathstringPath to the source PDF.
pageIndexintZero-based index of the page to render.
outputStreamStreamWritable destination stream.
optionsPdfRenderOptionsRender options.
compressionLevelintPNG compression level
0-9. Default6.cancellationTokenCancellationTokenCancels the operation.
Examples
using System.IO;
using LMKit.Document.Pdf;
// Stream a page preview straight into an HTTP response body
// (e.g. an ASP.NET endpoint serving a PDF thumbnail).
using MemoryStream output = new();
PdfRenderer.SavePageAsPng("report.pdf", pageIndex: 0, output);
byte[] payload = output.ToArray();