nebulae.dotPdfium
0.4.0
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
<PackageReference Include="nebulae.dotPdfium" Version="0.4.0" />
<PackageVersion Include="nebulae.dotPdfium" Version="0.4.0" />
<PackageReference Include="nebulae.dotPdfium" />
paket add nebulae.dotPdfium --version 0.4.0
#r "nuget: nebulae.dotPdfium, 0.4.0"
#:package nebulae.dotPdfium@0.4.0
#addin nuget:?package=nebulae.dotPdfium&version=0.4.0
#tool nuget:?package=nebulae.dotPdfium&version=0.4.0
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.
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 toPdfPageText
to avoid confusion with thePdfTextObject
class. - Added the nebulae.dotPDFium.Drawing namespace for drawing; currently supports
DrawLine()
andDrawRect()
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 | Versions 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. |
-
net8.0
- System.Drawing.Common (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.