OxidizePdf.NET 0.14.0

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

OxidizePdf.NET

NuGet License: MIT .NET

.NET bindings for oxidize-pdf - Fast, memory-safe PDF text extraction optimized for RAG/LLM pipelines with intelligent chunking.

Features

  • πŸš€ High Performance - Native Rust speed (3,000-4,000 pages/second)
  • 🧠 AI/RAG Optimized - Intelligent text chunking with sentence boundaries
  • πŸ›‘οΈ Memory Safe - Zero-copy FFI with automatic resource management
  • 🌍 Cross-Platform - Linux, Windows, macOS (x64)
  • πŸ“¦ Zero Dependencies - Self-contained native binaries in NuGet package
  • πŸ” Metadata Rich - Page numbers, confidence scores, bounding boxes

Installation

dotnet add package OxidizePdf.NET

Quick Start

Basic Text Extraction

using OxidizePdf.NET;

// Extract all text from PDF
using var extractor = new PdfExtractor();
byte[] pdfBytes = File.ReadAllBytes("document.pdf");

string text = await extractor.ExtractTextAsync(pdfBytes);
Console.WriteLine(text);

OxidizePdf.NET mirrors the RAG-first surface of the Python bridge (oxidize-python). Token-aware, structure-aware chunks ready for vector store ingestion in one call:

using OxidizePdf.NET;
using OxidizePdf.NET.Pipeline;

var extractor = new PdfExtractor();
var chunks = await extractor.RagChunksAsync(pdfBytes, ExtractionProfile.Rag);
foreach (var c in chunks)
{
    // c.FullText  β€” text + heading context (use this for embeddings)
    // c.Text      β€” the chunk's own text
    // c.PageNumbers β€” 1-based source pages (cite results)
    // c.TokenEstimate β€” plan batch sizes / model windows
    // c.HeadingContext β€” section heading the chunk belongs to (or null)
}

Seven profiles: Standard, Academic, Form, Government, Dense, Presentation, Rag. For fine-grained control pass an explicit PartitionConfig (reading order, header/footer zones, table confidence) and/or HybridChunkConfig (max tokens, overlap, merge policy):

var partition = new PartitionConfig()
    .WithReadingOrder(ReadingOrderStrategy.XyCut(20.0))   // multi-column
    .WithMinTableConfidence(0.7);
var hybrid = new HybridChunkConfig().WithMaxTokens(256).WithOverlap(32);
var chunks = await extractor.RagChunksAsync(pdfBytes, partition, hybrid);

Element-aware semantic chunks (titles/tables kept whole):

var semantic = await extractor.SemanticChunksAsync(
    pdfBytes,
    new SemanticChunkConfig(maxTokens: 512));

Markdown export with explicit options (RAG-012):

using OxidizePdf.NET.Ai;
var md = await extractor.ToMarkdownAsync(
    pdfBytes,
    new MarkdownOptions { IncludeMetadata = true, IncludePageNumbers = true });

Standalone text chunker (no PDF β€” for non-PDF sources):

using OxidizePdf.NET.Ai;
var chunker = new DocumentChunker(chunkSize: 512, overlap: 50);
var pieces = chunker.ChunkText(rawText);
var tokens = DocumentChunker.EstimateTokens(rawText);

End-to-end vector-store ingestion with KernelMemory:

using OxidizePdf.NET;
using OxidizePdf.NET.Pipeline;
using Microsoft.KernelMemory;

var extractor = new PdfExtractor();
var memory = new KernelMemoryBuilder().Build();

var chunks = await extractor.RagChunksAsync(pdfBytes, ExtractionProfile.Rag);

foreach (var c in chunks)
{
    await memory.ImportTextAsync(
        text: c.FullText,
        documentId: $"doc_p{c.PageNumbers[0]}_c{c.ChunkIndex}",
        tags: new Dictionary<string, object>
        {
            ["source"] = "SharePoint/Documents/report.pdf",
            ["pages"] = string.Join(",", c.PageNumbers),
            ["heading"] = c.HeadingContext ?? string.Empty,
            ["tokens"] = c.TokenEstimate,
        });
}

Legacy character-based chunking (ChunkOptions + ExtractChunksAsync) is marked [Obsolete] since 0.9.0-rag.1 and will be removed one minor release later. Prefer the token-aware overloads above.

SharePoint Crawler Example

using OxidizePdf.NET;
using Microsoft.Graph;

var extractor = new PdfExtractor();
var graphClient = new GraphServiceClient(...);

// Crawl SharePoint document library
var driveItems = await graphClient.Sites["root"]
    .Drives["Documents"]
    .Root
    .Children
    .Request()
    .Filter("endsWith(name,'.pdf')")
    .GetAsync();

foreach (var item in driveItems)
{
    var stream = await graphClient.Sites["root"]
        .Drives["Documents"]
        .Items[item.Id]
        .Content
        .Request()
        .GetAsync();

    using var ms = new MemoryStream();
    await stream.CopyToAsync(ms);

    var chunks = await extractor.ExtractChunksAsync(ms.ToArray());

    // Process chunks for embeddings...
}

Performance

Based on oxidize-pdf v1.6.4 benchmarks:

  • Text Extraction: 3,000-4,000 pages/second
  • Chunking: 0.62ms for 100 pages
  • Memory Overhead: <1MB per document
  • PDF Parsing: 98.8% success rate on 759 real-world PDFs

Supported Platforms

Platform Runtime Identifier Status
Linux x64 linux-x64 βœ… Supported
Windows x64 win-x64 βœ… Supported
macOS x64 osx-x64 βœ… Supported

Native binaries are automatically included in the NuGet package.

Architecture

  • native/ - Rust FFI layer (cdylib)
  • dotnet/ - C# wrapper with P/Invoke
  • examples/ - Integration examples (KernelMemory, BasicUsage)

See ARCHITECTURE.md for detailed design decisions.

API Reference

PdfExtractor

public class PdfExtractor : IDisposable
{
    // Extract plain text from PDF
    public Task<string> ExtractTextAsync(byte[] pdfBytes);

    // Extract text chunks optimized for RAG/LLM
    public Task<DocumentChunks> ExtractChunksAsync(
        byte[] pdfBytes,
        ChunkOptions options = null
    );

    // Extract metadata (page count, title, author)
    public Task<PdfMetadata> ExtractMetadataAsync(byte[] pdfBytes);
}

ChunkOptions

public class ChunkOptions
{
    public int MaxChunkSize { get; set; } = 512;          // Max tokens per chunk
    public int Overlap { get; set; } = 50;                // Overlap between chunks
    public bool PreserveSentenceBoundaries { get; set; } = true;
    public bool IncludeMetadata { get; set; } = true;
}

DocumentChunk

public class DocumentChunk
{
    public int Index { get; set; }             // Chunk index in document
    public int PageNumber { get; set; }        // Source page number
    public string Text { get; set; }           // Chunk text content
    public double Confidence { get; set; }     // Extraction confidence (0.0-1.0)
    public BoundingBox BoundingBox { get; set; } // Optional spatial info
}

Requirements

  • .NET 8.0+ (tested on .NET 8, 9)
  • Native Runtime: Automatically included in NuGet package

Note: .NET 6 support was dropped in v0.2.0 as it reached end-of-support in November 2024. Use v0.1.0 if you still require .NET 6 compatibility.

Building from Source

# Clone repository
git clone https://github.com/bzsanti/oxidize-pdf-dotnet.git
cd oxidize-pdf-dotnet

# Build native library
cd native
cargo build --release

# Build .NET wrapper
cd ../dotnet
dotnet build

# Run tests
dotnet test

Examples

See examples/ directory:

  • BasicUsage/ - Simple text extraction
  • KernelMemory/ - Full SharePoint crawler with RAG pipeline

License

This project is licensed under the MIT License - see LICENSE file.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

Acknowledgments

Built on top of oxidize-pdf by Santiago FernΓ‘ndez MuΓ±oz.

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 is compatible.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OxidizePdf.NET:

Package Downloads
OxidizePdf.NET.KernelMemory

Kernel Memory content decoder backed by oxidize-pdf: structure-aware, page-cited PDF chunks dropped into your KM RAG pipeline in one call.

GitHub repositories

This package is not used by any popular GitHub repositories.