PdfiumRaster 2.0.3

dotnet add package PdfiumRaster --version 2.0.3
                    
NuGet\Install-Package PdfiumRaster -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PdfiumRaster" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PdfiumRaster" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="PdfiumRaster" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PdfiumRaster --version 2.0.3
                    
#r "nuget: PdfiumRaster, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PdfiumRaster@2.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PdfiumRaster&version=2.0.3
                    
Install as a Cake Addin
#tool nuget:?package=PdfiumRaster&version=2.0.3
                    
Install as a Cake Tool

PdfiumRaster

NuGet CI CodeQL OpenSSF Scorecard License: MIT

PdfiumRaster is a .NET Standard library for rendering PDF pages to BMP, PNG, JPEG, or WebP images. PDFium handles page rendering; SkiaSharp handles compressed image encoding.

This project is intentionally limited to PDF-to-image conversion. It does not provide PDF editing, text extraction, form filling, signing, or a viewer UI.

Features

  • Render one page, selected pages, or a complete document
  • Load PDFs from paths, streams, byte arrays, or Base64 strings
  • Set DPI, output dimensions, rotation, background, annotations, and anti-aliasing
  • Produce color, grayscale, or thresholded black-and-white output
  • Query page count and page dimensions
  • Reuse document and bitmap resources for repeated rendering
  • Save directly from PDFium-owned pixel memory without a full-page managed buffer
  • Queue unrelated render requests with bounded backpressure
  • Restore native PDFium and SkiaSharp runtime assets through NuGet

PdfiumRaster And PDFiumCore

PDFiumCore and PdfiumRaster call the same native PDFium renderer, but they serve different layers. PDFiumCore generates broad .NET bindings for the PDFium C API. PdfiumRaster provides an owned, rendering-only workflow on top of a small direct native surface.

Concern PdfiumRaster PDFiumCore
Main job Convert PDF pages to BMP, PNG, JPEG, or WebP Expose PDFium functions and native handles
Ownership Manages initialization, callbacks, render buffers, and normal cleanup The application composes and closes native resources
Concurrency Serializes PDFium calls and can overlap image encoding The application supplies its own threading policy
Best fit Reliable PDF-to-image conversion Direct access to PDFium beyond a rendering workflow

Choose PdfiumRaster when the goal is reliable PDF-to-image conversion without building an interop and encoding layer. Choose PDFiumCore when the application needs lower-level PDFium features or precise control beyond PdfiumRaster's focused rendering API. See the detailed comparison for equivalent code, ownership, memory behavior, benchmarks, and the additive safety roadmap.

Requirements

The library targets netstandard2.1. The application using it must run on a Windows, Linux, or macOS runtime identifier supported by the PDFium and SkiaSharp packages in the dependency graph.

Installation

dotnet add package PdfiumRaster

No manual PDFium copy step is required for supported runtime identifiers.

PdfiumRaster 2.0 and later require a runtime that implements .NET Standard 2.1. .NET Framework and other netstandard2.0-only consumers should remain on PdfiumRaster 1.0.x.

Multi-process Rendering

For parallel rendering through isolated PDFium worker processes, see the separate PdfiumRaster.Orchestrator repository.

Quick Start

Render the first page to PNG. Page-number methods use 1-based numbers:

using PdfiumRaster;

PdfImageConverter.SavePng("input.pdf", pageNumber: 1, "page-0001.png");

The default render resolution is 300 DPI. For previews, select the 96-DPI preset explicitly:

PdfImageConverter.SavePng(
    "input.pdf",
    pageNumber: 1,
    "preview.png",
    new PdfImageConversionOptions
    {
        Render = PdfPageRenderOptions.ScreenPreview,
    });

Export every page as PNG:

int pageCount = PdfImageConverter.SaveDocument(
    "input.pdf",
    "images",
    options: new PdfImageConversionOptions
    {
        Format = PdfImageOutputFormat.Png,
        Render = new PdfPageRenderOptions { Dpi = 150 },
    });

Files are named with 1-based page numbers:

images/page-0001.png
images/page-0002.png

Page Indexes And Page Numbers

Methods named RenderPage or SavePage take a zero-based pageIndex. Methods named RenderPageNumber or SavePageNumber take a 1-based pageNumber.

PdfImageConverter.SavePage("input.pdf", pageIndex: 0, "index.bmp");
PdfImageConverter.SavePageNumber("input.pdf", pageNumber: 1, "number.bmp");

Batch methods follow the same convention:

PdfImageConverter.SavePages("input.pdf", new[] { 0, 2 }, "images");
PdfImageConverter.SavePageNumbers("input.pdf", new[] { 1, 3 }, "images");

Render And Encoding Options

var options = new PdfImageConversionOptions
{
    Format = PdfImageOutputFormat.Jpeg,
    ColorMode = PdfImageColorMode.Grayscale,
    Encoding = new PdfImageEncodingOptions
    {
        Quality = 85,
    },
    Render = new PdfPageRenderOptions
    {
        Dpi = 150,
        Width = 1600,
        WithAspectRatio = true,
        Rotation = PdfPageRotation.Normal,
        Flags = PdfRenderFlags.Annot | PdfRenderFlags.LcdText,
        AntiAliasing = PdfAntiAliasing.All,
        BackgroundColor = 0xFFFFFFFF,
    },
};

PdfImageConverter.SavePageNumber("input.pdf", pageNumber: 1, "page.jpg", options);

When WithAspectRatio is true, set either Width or Height, not both. Dimensions are pixels; PDF page dimensions reported by GetPageSizes are PDF points (72 points per inch).

PdfImageEncodingOptions.Fast selects PNG compression level 1 and JPEG/WebP quality 85. It favors encoding speed; the PNG may be larger, and JPEG/WebP output is lossy.

Input And Memory Behavior

For large PDFs, use a file path or seekable stream. Seekable streams use PDFium random-access callbacks and are not copied into one managed byte array.

using var input = File.OpenRead("input.pdf");
PdfBitmap bitmap = PdfImageConverter.RenderPage(
    input,
    pageIndex: 0,
    leaveOpen: true);
  • Input streams are disposed by default. Pass leaveOpen: true when the caller owns the stream.
  • Output stream overloads leave the destination stream open.
  • Non-seekable input streams are buffered once because PDFium requires random access; the backing buffer remains in managed memory for the open document lifetime.
  • Byte-array and Base64 APIs keep the complete PDF in managed memory.
  • Returned PdfBitmap pixels are BGRA and owned by the caller.
  • Rendered bitmap memory grows with output width and height, regardless of the source PDF file size.

Repeated Rendering

Use PdfRenderSession for several operations on the same PDF. It keeps the document open and reuses its current page and render buffer where possible.

using var session = PdfRenderSession.Open("input.pdf");
var options = new PdfImageConversionOptions
{
    Format = PdfImageOutputFormat.Png,
    Render = PdfPageRenderOptions.ScreenPreview,
    Encoding = PdfImageEncodingOptions.Fast,
};

Directory.CreateDirectory("images");

for (var pageIndex = 0; pageIndex < session.PageCount; pageIndex++)
{
    session.SavePage(pageIndex, $"images/page-{pageIndex + 1:D4}.png", options);
}

A session accepts one operation at a time. Its callback render overload exposes a session-owned bitmap that is valid only for the duration of the callback; do not retain that bitmap or its pixel array.

Concurrent Requests

Use one shared PdfRenderDispatcher when unrelated PDFs arrive concurrently. It provides a bounded asynchronous queue and can encode completed images on multiple workers.

using var dispatcher = new PdfRenderDispatcher(new PdfRenderDispatcherOptions
{
    QueueCapacity = 32,
    EncodingConcurrency = 2,
    QueueFullMode = PdfRenderQueueFullMode.Wait,
});

var options = new PdfImageConversionOptions
{
    Format = PdfImageOutputFormat.Png,
    Render = PdfPageRenderOptions.ScreenPreview,
};

await Task.WhenAll(
    dispatcher.SavePageAsync("first.pdf", pageIndex: 0, "first.png", options),
    dispatcher.SavePageAsync("second.pdf", pageIndex: 0, "second.png", options));

await dispatcher.CompleteAsync();

PDFium calls remain serialized process-wide; the dispatcher does not render two pages inside PDFium simultaneously. It improves request backpressure and allows encoding/output to overlap. Use supervised worker processes if native rendering must run in parallel or untrusted PDFs need stronger isolation.

Operational Safety

PDFium is native code parsing potentially untrusted input. Keep PdfiumRaster and its dependencies current. Applications that accept untrusted PDFs should limit input size, page count, output dimensions, DPI, total rendered pixels, and execution time. Public argument validation does not impose application-specific resource limits.

Documentation

Development

The repository uses the root Makefile as its command surface:

make restore
make build
make test
make pack

See the contribution guide before opening a pull request.

License

PdfiumRaster is available under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on PdfiumRaster:

Package Downloads
PdfiumRaster.Orchestrator

Multi-process PDFium rendering for PdfiumRaster over local named pipes.

PdfiumRaster.Orchestrator.osx-x64

Multi-process PDFium rendering for PdfiumRaster over local named pipes.

PdfiumRaster.Orchestrator.win-arm64

Multi-process PDFium rendering for PdfiumRaster over local named pipes.

PdfiumRaster.Orchestrator.win-x86

Multi-process PDFium rendering for PdfiumRaster over local named pipes.

PdfiumRaster.Orchestrator.linux-musl-x64

Multi-process PDFium rendering for PdfiumRaster over local named pipes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.3 44 8/7/2026
2.0.2 74 8/5/2026
2.0.1 2,245 7/22/2026
2.0.0 139 7/20/2026
1.0.0 97 7/17/2026
0.4.0 110 7/16/2026
0.3.0 103 7/15/2026
0.2.0-beta.0 68 6/30/2026
0.1.0-beta.5 51 7/15/2026
0.1.0-beta.3 71 6/21/2026
0.1.0-beta.2 71 6/21/2026
0.1.0-beta.1 61 6/20/2026

Fixes owned input-stream cleanup when PdfRenderDispatcher requests fail before queue admission.