Hypapdf 0.1.0
dotnet add package Hypapdf --version 0.1.0
NuGet\Install-Package Hypapdf -Version 0.1.0
<PackageReference Include="Hypapdf" Version="0.1.0" />
<PackageVersion Include="Hypapdf" Version="0.1.0" />
<PackageReference Include="Hypapdf" />
paket add Hypapdf --version 0.1.0
#r "nuget: Hypapdf, 0.1.0"
#:package Hypapdf@0.1.0
#addin nuget:?package=Hypapdf&version=0.1.0
#tool nuget:?package=Hypapdf&version=0.1.0
Hypapdf for .NET
A fast, dependency-free PDF reader for .NET. Opens PDFs, exposes their structure and metadata, decodes streams and extracts text with glyph positions. Text extraction is 5 to 35 times faster than every other open-source .NET option measured, native PDFium and MuPDF included. Safe for untrusted input, and thread-safe so pages can be read in parallel.
Hypapdf is a sibling of Hypaxel, the streaming XLSX library, and follows the same rules: no runtime dependencies, reproducible benchmarks against the libraries you would otherwise use, and input treated as hostile.
When to use it
- Index or search PDFs (document stores, RAG pipelines, e-discovery): extract the text of many documents quickly.
- Read invoices, forms and reports in a web service: text, filled-in form fields, metadata, page geometry.
- Inspect PDFs: page count, version, encryption, the raw object model and decoded streams.
Hypapdf reads; it does not render, edit or write PDFs, and it does not run OCR on scanned pages.
Install
dotnet add package Hypapdf
Targets .NET 8, 9, 10 and 11. No other packages are needed.
Quick look
using Hypapdf;
using var pdf = await PdfDocument.OpenAsync("report.pdf"); // or Open(byte[] | ReadOnlyMemory<byte> | Stream)
Console.WriteLine($"{pdf.PageCount} pages, PDF {pdf.Version}, title: {pdf.Info.Title}");
foreach (var page in pdf.Pages)
{
Console.WriteLine(page.ExtractText());
}
// All pages at once, on every processor; pages are separated by form feeds.
string all = pdf.ExtractText(new PdfTextOptions { MaxDegreeOfParallelism = 0 });
// Reading order for multi-column pages: blocks (paragraphs, columns, cells) column by column.
string ordered = pdf.Pages[0].ExtractText(new PdfTextOptions { Layout = PdfTextLayout.ReadingOrder });
foreach (var block in pdf.Pages[0].GetTextBlocks())
{
Console.WriteLine($"{block.Bounds}: {block.Text}"); // block.Lines[i].Words[j].Bounds, FontName, ...
}
// Form fields: names, types, values, options and the pages they are on.
foreach (var field in pdf.FormFields)
{
Console.WriteLine($"{field.FullName} ({field.Type}, page {field.PageNumber}) = {field.Value}");
}
// Images: JPEG and JPEG 2000 bytes as stored, other images as PNG.
foreach (var image in pdf.Pages[0].GetImages())
{
var bytes = image.Format == PdfImageFormat.Raw ? image.ToPng() : image.GetEncodedData();
if (bytes is not null) File.WriteAllBytes($"image-{image.Name}{image.FileExtension}", bytes);
}
// Bookmarks and links.
foreach (var item in pdf.Outlines)
{
Console.WriteLine($"{item.Title} -> page {item.PageNumber}"); // item.Children, item.Uri, item.Destination
}
foreach (var link in pdf.Pages[0].GetLinks())
{
Console.WriteLine($"{link.Bounds}: {link.Uri ?? $"page {link.PageNumber}"}");
}
// Glyphs with their positions in user space (points, origin bottom left).
foreach (var letter in pdf.Pages[0].GetLetters())
{
Console.WriteLine($"{letter.Value} at ({letter.X:F1}, {letter.Y:F1}) size {letter.FontSize:F1} {letter.FontName}");
}
Encrypted documents open with the empty password, or with new PdfReadOptions { Password = "..." } (user or owner
password). In ASP.NET Core, read an upload with await PdfDocument.OpenAsync(request.Body).
Features
| Area | Supported |
|---|---|
| File structure | Cross-reference tables and streams, hybrid files, incremental updates, object streams, linearized files, junk before the header, wrong /Length values; damaged or missing cross-reference data is rebuilt by scanning the file (WasRepaired) |
| Filters | FlateDecode (tolerates missing headers, bad checksums and truncation), LZWDecode, ASCII85Decode, ASCIIHexDecode, RunLengthDecode, PNG and TIFF predictors; image filters (DCT, JPX, JBIG2, CCITT) are left encoded |
| Encryption | Standard security handler: RC4 40–128 bit, AES-128, AES-256 (revisions 2–6), crypt filters, user and owner passwords, permissions |
| Pages | Page tree with inherited resources, media box, crop box and rotation; decoded content streams |
| Metadata | Document information (title, author, subject, keywords, creator, producer, dates), XMP, version |
| Layout | Words, lines and blocks with bounding boxes, font and rotation; reading order across columns (recursive XY cut on blocks), text in other directions laid out in its own frame |
| Text | Content order with spaces and line breaks from glyph positions; simple fonts (standard encodings, Differences, Adobe Glyph List, built-in Type 1 encodings, Type 3), composite fonts (ToUnicode, embedded and predefined CMaps including Shift JIS, EUC, GBK, Big Five and UHC, embedded TrueType cmap and post tables), vertical writing, Form XObjects, annotation appearances such as filled-in form fields, fake-bold duplicates removed, Latin ligatures expanded |
| Images | Image XObjects (also inside Form XObjects and annotation appearances) and inline images, with the rectangle each covers on the page, size, colour space, bits per component and format; JPEG and JPEG 2000 data as stored; raw images in gray, RGB, CMYK, indexed and ICC-based spaces and image masks converted to PNG |
| Navigation | Bookmarks (outline tree) and link annotations with explicit and named destinations (name tree and old-style /Dests), GoTo, GoToR, Launch and URI actions, fit types and coordinates |
| Forms | AcroForm fields with inherited attributes: text, check box, radio group, push button, combo box, list box (multi-select) and signature; full names, values and defaults, options with export values and display texts, flags, tooltips, and each widget's page and rectangle. XFA-only forms are not read |
| Object model | Dictionaries, arrays, streams, names, strings (PDFDocEncoding, UTF-16, UTF-8), numbers, references; GetObject, Resolve, Catalog, Trailer |
API
| Member | Description |
|---|---|
PdfDocument.OpenAsync(path \| Stream, PdfReadOptions?, CancellationToken), Open(byte[] \| ReadOnlyMemory<byte> \| Stream, PdfReadOptions?) |
Opens a document; files are read asynchronously, data already in memory synchronously. Only the cross-reference data is read; everything else is parsed on first use. |
PageCount, Pages, Info, Version, IsEncrypted, Permissions, WasRepaired, XmpMetadata |
Document properties. |
ExtractText(PdfTextOptions?) |
Text of all pages, separated by \f. |
Outlines |
The bookmark tree (PdfOutlineItem: Title, PageNumber, Uri, Destination, Children, IsOpen). |
FormFields |
The terminal fields of the interactive form (PdfFormField: FullName, Type, Value, Values, IsChecked, Options, Widgets, PageNumber, flags). |
Catalog, Trailer, GetObject(int), Resolve(PdfObject) |
The object model. |
PdfPage.ExtractText(PdfTextOptions?), GetLetters() |
Text of one page, or every glyph with its position, size and font. |
PdfPage.GetImages(bool includeAnnotations = true) |
The images drawn on the page (PdfImage: Width, Height, ColorSpace, Format, Bounds, GetEncodedData(), ToPng()). |
PdfPage.GetLinks() |
The link annotations (PdfLink: Bounds, PageNumber, Uri, RemoteFile, Destination). |
PdfPage.GetWords(PdfTextOptions?), GetTextBlocks(PdfTextOptions?) |
Words with bounding boxes in content order; blocks of lines of words in reading order. |
PdfPage.MediaBox, CropBox, Rotation, Width, Height, Resources, Dictionary, GetContentData() |
Page properties. |
PdfStream.GetData(), GetRawData() |
Decoded and raw stream bytes. |
PdfTextOptions: Layout (ContentOrder, the fastest, or ReadingOrder), MaxDegreeOfParallelism (1; 0 = all processors), IncludeAnnotations (true), WordGapRatio
(0.15 of the font size), LineGapRatio (0.5), RemoveDuplicateGlyphs (true).
PdfReadOptions: Password, MaxDecodedStreamBytes (256 MiB), MaxObjects (16 million), MaxFormDepth (32).
Errors: PdfFormatException when the input is not a PDF or is damaged beyond repair (or a stream exceeds the
decoding limit), PdfEncryptedException when a password is needed or wrong, or the document uses a public-key
security handler. Malformed input is meant to surface only as these exceptions, never as a crash or a hang; mutation
fuzzing over the pdf.js test suite (50,000 damaged files so far) checks this.
Threads. PdfDocument, PdfPage and the object model are safe to use from several threads at once.
Memory. The file is held in memory (a byte[] you pass is used in place, not copied); decoded page content
is pooled and released after each page.
Performance
Every open-source .NET library that can read PDF text was measured on the same files, each in its own process, best of several passes, one document after another on one thread unless noted:
- PdfPig 0.1.16 (
ContentOrderTextExtractor), managed - iText 9.8.1 (
SimpleTextExtractionStrategy, the content-order strategy), managed - PDFium, the engine of Chrome's PDF viewer: called directly through PDFiumCore 4688 with pdfium-binaries 160.0.8193, and through Docnet.Core 2.6.0
- MuPDF.NET 4.1.2 (MuPDF 1.28.6), Linux only because it ships no macOS arm64 binaries
- PDFsharp 6.2.4, which has no text extraction and is measured for opening only
Real-world documents (dotnet/benchmarks/fetch-corpus.sh: the ISO 32000-1 specification, IRS Publication 17 and form
1040, two arXiv papers, Free Culture, two papers from the pdf.js test suite; 8 files, 31 MiB, 1,298 pages).
Apple M1 Max, .NET 10; macOS 26 natively, and Linux arm64 in a Podman container (dotnet/benchmarks/Containerfile):
| Library | Extract text, macOS | Extract text, Linux | Open + page count, macOS | Open, Linux |
|---|---|---|---|---|
| Hypapdf | 283 ms | 322 ms | 23 ms | 32 ms |
| Hypapdf, pages in parallel | 85 ms | 116 ms | ||
| PDFium (PDFiumCore) | 1,503 ms (5.3×) | 1,752 ms (5.4×) | 30 ms | 34 ms |
| PdfPig | 2,053 ms (7.3×) | 2,529 ms (7.9×) | 108 ms | 177 ms |
| iText | 3,057 ms (10.8×) | 3,579 ms (11.1×) | 624 ms | 789 ms |
| Docnet (PDFium) | 3,214 ms (11.4×) | 3,441 ms (10.7×) | 39 ms | 49 ms |
| MuPDF.NET | — | 11,411 ms (35×) | — | 48 ms |
| PDFsharp | — | — | 1,122 ms | 1,233 ms |
Factors are relative to Hypapdf on one thread. The order is the same on x86-64 (a linux/amd64 container emulated
with Rosetta, so only the ratios mean anything): Hypapdf 499 ms, PdfPig 3,296 ms, PDFium 4,013 ms, Docnet 4,269 ms,
iText 5,201 ms, MuPDF.NET 13,441 ms (dotnet/benchmarks/results/linux-x64-emulated.txt). Hypapdf allocates 76 MiB for the text run, against 2.5 GiB for
PdfPig and 6.5 GiB for iText. Hypapdf, PdfPig, iText and PDFium return the same amount of text (3.24 million
non-whitespace characters, within 0.1%); MuPDF returns 2% less.
The pdf.js test suite (692 small, often damaged or unusual files, 77 MiB; Linux):
| Library | Extract text | Files read |
|---|---|---|
| Hypapdf | 493 ms | 688 |
| PDFium (PDFiumCore) | 1,377 ms | 683 |
| Docnet (PDFium) | 2,317 ms | 682 |
| iText | 3,627 ms | 644 |
| MuPDF.NET | 9,796 ms | 685 |
| PdfPig | crashes | — |
Hypapdf's 4 failures are password-protected or damaged files that Poppler's pdftotext gets nothing from either.
PdfPig could not be measured, because files such as issue19800.pdf kill the process with a stack overflow, which
.NET cannot catch.
Not measured: Docotic.Pdf and IronPDF, which do not run without a licence key; other commercial libraries; and
Free Spire.PDF, whose free edition reads only the first 10 pages of a document. All figures come from one Apple M1
Max that was running other work (load average 7 to 13) during the runs; every library ran under the same load, best
of several passes, and the ratios held across reruns. There is no native x86-64 measurement yet.
Reproduce with cd dotnet/benchmarks && ./fetch-corpus.sh && ./run.sh
(or the Containerfile); the raw output is in dotnet/benchmarks/results/.
Why it is fast
- The file stays in memory and is parsed lazily, straight from bytes: no stream abstraction, no tokens as objects.
- The lexer parses numbers in a single pass; names are interned per document without locks on lookup.
- Fonts are compiled once per document into code-indexed tables of widths and Unicode strings, so a glyph costs two array reads; text is appended without allocating per glyph.
- Page content is inflated (and decrypted) into pooled buffers; the text builder is reused per thread.
- Pages are independent and the document is thread-safe, so
ExtractTextcan use every core.
Text quality
Hypapdf extracts text in content order, like pdftotext -raw, inserting spaces and line breaks from the glyph
positions. Over the 210 files of the pdf.js test suite with text, its output matches pdftotext -raw (Poppler) with
a word-level F1 of 0.95 weighted by length; most of the remaining differences are files where one of the two
produces garbage (custom encodings without ToUnicode), dot leaders, or annotations Poppler draws differently.
Limitations
- Reading order is geometric (columns and bands of blocks); it does not use the tagged-PDF structure tree, and forms and complex tables may still come out in an order a person would not choose. It costs about twice the time of content order.
- Composite fonts that have neither a ToUnicode map nor an embedded TrueType cmap only map the ASCII range of the Adobe CJK collections; full CID-to-Unicode tables are not included.
- Right-to-left text is returned in visual (drawing) order.
- CFF font programs are not parsed for built-in encodings.
- Images are not decoded from JPEG, JPEG 2000, JBIG2 or CCITT (their bytes are returned as stored), soft masks are
not applied in
ToPng, and images that only serve as soft masks are not listed. - Files larger than 2 GB and public-key encryption are not supported.
Development
dotnet format --verify-no-changes && dotnet build -c Release && dotnet test -c Release
dotnet run --project tools/Hypapdf.Cli -c Release -- text file.pdf # also: info, fonts, letters, corpus, fuzz
Run these from dotnet/. Test files are generated by testdata/generate.py with
ReportLab, pypdf and fontTools. AGENTS.md and the repository's AGENTS.md describe the
layout and the rules for changes.
License
Apache License 2.0, copyright vensas GmbH. Third-party data (the Adobe Glyph List, the standard encodings and Core14 metrics) is listed in NOTICE.
| 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 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
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.1.0 | 0 | 12/2/2026 |