CommunityToolkit.DocumentExtraction.PdfPig 1.0.0-preview

Prefix Reserved
This is a prerelease version of CommunityToolkit.DocumentExtraction.PdfPig.
dotnet add package CommunityToolkit.DocumentExtraction.PdfPig --version 1.0.0-preview
                    
NuGet\Install-Package CommunityToolkit.DocumentExtraction.PdfPig -Version 1.0.0-preview
                    
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="CommunityToolkit.DocumentExtraction.PdfPig" Version="1.0.0-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommunityToolkit.DocumentExtraction.PdfPig" Version="1.0.0-preview" />
                    
Directory.Packages.props
<PackageReference Include="CommunityToolkit.DocumentExtraction.PdfPig" />
                    
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 CommunityToolkit.DocumentExtraction.PdfPig --version 1.0.0-preview
                    
#r "nuget: CommunityToolkit.DocumentExtraction.PdfPig, 1.0.0-preview"
                    
#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 CommunityToolkit.DocumentExtraction.PdfPig@1.0.0-preview
                    
#: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=CommunityToolkit.DocumentExtraction.PdfPig&version=1.0.0-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CommunityToolkit.DocumentExtraction.PdfPig&version=1.0.0-preview&prerelease
                    
Install as a Cake Tool

CommunityToolkit.DocumentExtraction.PdfPig

Extract text and page geometry from searchable PDFs without sending documents to a service. Results are returned as a provider-neutral ExtractionDocument graph with text blocks, optional roles and source references. Use it for PDFs that already contain text; scanned images require an OCR provider.

Local model-driven layout, rendering and OCR/table inference are planned as a separate advanced companion, not part of this package. This basic provider has no ONNX Runtime, model weights or native PDF-rendering dependency.

Install

dotnet add package CommunityToolkit.DocumentExtraction.PdfPig --prerelease

For MEDE0001 or EXTEXP0019 compiler diagnostics, see experimental API opt-in.

Requirements and dependencies

Experimental APIs emit CTDE0001; opt in explicitly as described in the component guide.

Targets .NET Standard 2.0 and .NET 10. See the runtime support policy. The package brings these runtime dependencies transitively; consumers do not need to install them separately:

  • PdfPig 0.1.15 for PDF parsing, word extraction and segmentation.
  • Microsoft.Extensions.DocumentExtraction.Abstractions, Microsoft.Extensions.Documents.Abstractions and Microsoft.Extensions.AI.Abstractions for extraction options, document structure and content payloads.

There are no Azure credentials, model deployments, native PDF renderer or model downloads to configure. The examples below need only this provider package.

Examples

Extract text from a PDF

Complete console example. Supply an existing searchable document.pdf. The timeout token covers reading and extraction; the caller owns the stream.

using System;
using System.IO;
using System.Linq;
using System.Threading;
using CommunityToolkit.DocumentExtraction.PdfPig;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Documents;

using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(2));
using var extractor = new PdfPigDocumentExtractionClient();
using var input = File.OpenRead("document.pdf");
ExtractionDocument document = await extractor.ExtractAsync(
    input, "document.pdf", "application/pdf", cancellationToken: timeout.Token);

foreach (var text in document.EnumerateContent().OfType<ExtractionDocumentTextElement>())
{
    Console.WriteLine(((TextContent)text.Content!).Text);
}

TextContent.Text is the text payload. Sections and other structural ancestors do not contain copies of descendant text; tables and images are not inferred from these text blocks.

Read page geometry and native text blocks

Continuation of the first example; no additional package is needed.

using UglyToad.PdfPig.DocumentLayoutAnalysis;

foreach (var text in document.EnumerateContent().OfType<ExtractionDocumentTextElement>())
{
    foreach (var source in text.Sources)
    {
        Console.WriteLine($"Original page: {source.Page.PageNumber}");
        foreach (var point in source.Polygon)
        {
            Console.WriteLine($"({point.X}, {point.Y})");
        }

        if (source.GetRawRepresentation() is TextBlock block)
        {
            Console.WriteLine($"Native block: {block.Text}");
        }
    }
}

Every PDF page has a source frame, including blank pages. Block bounding boxes have four ordered vertices, in PDF points with a bottom-left origin. Native TextBlock objects are available on source references; there is no native PDF parser exposed through document.RawRepresentation.

Configure segmentation and roles

Alternative client construction; use this client in place of extractor above. PdfPig's types are available through the transitive PdfPig dependency.

using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;

using var configuredExtractor = new PdfPigDocumentExtractionClient(
    pageSegmenter: DefaultPageSegmenter.Instance,
    roleResolver: block => block.Text.StartsWith("Invoice", StringComparison.Ordinal)
        ? "heading"
        : null);

The role callback is an application heuristic, not heading detection performed by the provider. You can also supply an IWordExtractor. Injected helpers remain borrowed; adapter disposal does not dispose them.

Limitations and troubleshooting

  • Only application/pdf is accepted. An image-only PDF can yield page frames without text. Use an OCR-capable provider when text must be recognized.
  • DocumentExtractionOptions.ExtractorName must be absent or pdfpig. Additional properties and other selectors throw NotSupportedException.
  • Parsing/layout errors and cancellation propagate to the caller. The provider buffers the input in memory; account for file size and PDF complexity.
  • Dispose the client and input stream when finished. The provider leaves the caller's stream open; returned documents require no disposal.

Documentation and feedback

Licensed 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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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

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
1.0.0-preview 111 11/11/2026