nebulae.dotPdfium 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package nebulae.dotPdfium --version 0.4.0
                    
NuGet\Install-Package nebulae.dotPdfium -Version 0.4.0
                    
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="nebulae.dotPdfium" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nebulae.dotPdfium" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="nebulae.dotPdfium" />
                    
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 nebulae.dotPdfium --version 0.4.0
                    
#r "nuget: nebulae.dotPdfium, 0.4.0"
                    
#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 nebulae.dotPdfium@0.4.0
                    
#: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=nebulae.dotPdfium&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=nebulae.dotPdfium&version=0.4.0
                    
Install as a Cake Tool

dotPDFium

dotPDFium is an early-stage, .NET 8+ wrapper around the native PDFium library, aiming to provide a safe and idiomatic C# interface for loading, parsing, and rendering PDF files.

This project is currently in a pre-pre-alpha state. Development is focused on establishing core object lifecycles (PdfDocument, PdfPage, PdfText), managing native resource ownership correctly, and wrapping the lower-level PDFium API with a clean, maintainable surface.

We're not yet feature-complete, stable, or ready for production use. This repository is for exploratory development and incremental wrapping of PDFium's 449 functions in a .NET-friendly way.

The library contains the latest PDFium binaries (v138.0.7175.0) from chromium/7175, built by bblanchon (https://github.com/bblanchon/pdfium-binaries/releases) for Windows x64 & ARM64, Linux x64 & ARM64, and MacOS (as a universal dylib supporting x64 & ARM64).

We are at v0.4.0-prealpha, which is a very early pre-alpha version. The goal is to hit v1.0 within 3 months or so, maybe sooner. Prior to a v1.0 release, our minor version will serve to indicate the SemVer of the library, and the 3rd digit will indicate the build.

Feature requests, bug reports, and PRs are welcome. Please open an issue or PR if you have suggestions or want to help out.

As always, we can be reached at nebulae at nebulae dot online.

NuGet

Goals (eventually)

  • Managed lifecycle and memory safety for native PDFium handles (mostly done)
  • Optional exceptions or TryX() patterns for common workflows (WIP)
  • Modular text extraction and page rendering APIs (mostly feature complete)
  • MIT-licensed wrapper code with proper attribution to the PDFium project (Apache 2.0)

Recent Updates

2025-05-21

  • Renamed the PdfText class to PdfPageText to avoid confusion with the PdfTextObject class.
  • Added the nebulae.dotPDFium.Drawing namespace for drawing; currently supports DrawLine() and DrawRect() methods.
  • Added a fluent API for path drawing to the new Drawing namespace via the PathBuilder class.

Current Status

  • Basic document and page loading implemented
  • Page handling and rendering implemented
  • Text extraction imlemented
  • Search implemented
  • Security implemented
  • Forms* are a WIP; If you have suggestions, please open an issue or PR
  • Annotations imlemented
  • Very few formal tests
  • No documentation or examples yet
  • Structured trees and progressive loading are implemented
  • Basic Drawing API is implemented
  • XFA support is not planned
  • Javascript support is not planned
API Docs are available at dotPDFium API Docs
Getting Started can be found here
*Can I Create New Form Fields?

No — the underlying PDFium library does not support creating new /Widget annotations, which are required for checkboxes, text inputs, radio buttons, etc.

This is a limitation in the C++ PDFium core. Until it adds FPDF_ANNOT_WIDGET to its supported list, only editing of existing form fields is possible.

See: FPDFAnnot_IsSupportedSubtype


Note: This is a low-level interop library in early development. Expect sharp edges, breaking changes, and missing functionality.


Example Usage

Create a new PDF document
    using nebulae.dotPDFium;

    PDFiumEngine.Init();

    var doc = PdfDocument.CreateNew();
    var page = doc.CreatePage(0, 612, 792); // 8.5x11 inches

    var font = doc.LoadStandardFont("Helvetica");
    var text = doc.CreateTextObject(font, 12f);
    text.SetText("Hello from test!");
    text.SetPosition(100, 700);
    page.InsertObject(text);

    page.FinalizeContent();
    doc.SaveTo("generated.pdf");

    PDFiumEngine.Shutdown();
Cross platform rendering & drawing (using SixLabors' ImageSharp for cross-platform support)

    PDFiumEngine.Init();

    var doc = PdfDocument.LoadFromFile("test.pdf");
    using var page = doc.LoadPage(0);

    int dpi = 144;
    float scale = dpi / 72f;

    int width = (int)(page.Width * scale);
    int height = (int)(page.Height * scale);

    using var pdfBitmap = PdfBitmap.Create(width, height);
    pdfBitmap.FillRect(0, 0, width, height, 0xFFFFFFFF); // White background

    page.RenderToBitmap(pdfBitmap, 0, 0, width, height);

    var imageBuffer = new Rgba32[width * height];

    unsafe
    {
        Buffer.MemoryCopy(
            source: (void*)pdfBitmap.Buffer,
            destination: Unsafe.AsPointer(ref imageBuffer[0]),
            destinationSizeInBytes: imageBuffer.Length * sizeof(uint), // Rgba32 is 4 bytes
            sourceBytesToCopy: imageBuffer.Length * sizeof(uint)
        );
    }

    var image = Image.WrapMemory<Rgba32>(imageBuffer, width, height);

    // Apply ImageSharp.Drawing: draw a red rectangle on top of the rendered PDF
    image.Mutate(ctx =>
    {
        ctx.DrawPolygon(Color.Red, 4f, new PointF[]
        {
            new(50, 50),
            new(width - 50, 50),
            new(width - 50, height - 50),
            new(50, height - 50),
            new(50, 50)
        });
    });

    image.SaveAsPng("rendered-drawing.png");

    PDFiumEngine.Shutdown();

Installation

You can install the package via NuGet:


$ dotnet add package nebulae.dotPdfium

Or via git:


$ git clone https://github.com/nebulaeonline/dotPdfium.git
$ cd dotPdfium
$ dotnet build


License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.2.5 279 9/16/2025
0.4.2.4 140 9/11/2025
0.4.2.3 149 9/8/2025
0.4.2.2 83 8/15/2025
0.4.2.1 136 8/9/2025
0.4.2 218 8/6/2025
0.4.1 215 8/6/2025
0.4.0 215 8/6/2025