CommunityToolkit.DocumentExtraction.PdfPig
1.0.0-preview
Prefix Reserved
dotnet add package CommunityToolkit.DocumentExtraction.PdfPig --version 1.0.0-preview
NuGet\Install-Package CommunityToolkit.DocumentExtraction.PdfPig -Version 1.0.0-preview
<PackageReference Include="CommunityToolkit.DocumentExtraction.PdfPig" Version="1.0.0-preview" />
<PackageVersion Include="CommunityToolkit.DocumentExtraction.PdfPig" Version="1.0.0-preview" />
<PackageReference Include="CommunityToolkit.DocumentExtraction.PdfPig" />
paket add CommunityToolkit.DocumentExtraction.PdfPig --version 1.0.0-preview
#r "nuget: CommunityToolkit.DocumentExtraction.PdfPig, 1.0.0-preview"
#:package CommunityToolkit.DocumentExtraction.PdfPig@1.0.0-preview
#addin nuget:?package=CommunityToolkit.DocumentExtraction.PdfPig&version=1.0.0-preview&prerelease
#tool nuget:?package=CommunityToolkit.DocumentExtraction.PdfPig&version=1.0.0-preview&prerelease
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:
PdfPig0.1.15 for PDF parsing, word extraction and segmentation.Microsoft.Extensions.DocumentExtraction.Abstractions,Microsoft.Extensions.Documents.AbstractionsandMicrosoft.Extensions.AI.Abstractionsfor 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/pdfis accepted. An image-only PDF can yield page frames without text. Use an OCR-capable provider when text must be recognized. DocumentExtractionOptions.ExtractorNamemust be absent orpdfpig. Additional properties and other selectors throwNotSupportedException.- 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
- PdfPig documentation and supported PDF features
- Provider comparison and shared document model
- Report a Toolkit issue
Licensed under the MIT license.
| Product | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DocumentExtraction.Abstractions (>= 11.0.0-preview.1.26560.3)
- PdfPig (>= 0.1.15)
-
net10.0
- Microsoft.Extensions.DocumentExtraction.Abstractions (>= 11.0.0-preview.1.26560.3)
- PdfPig (>= 0.1.15)
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 |