A pure-managed, cross-platform .NET library for creating, reading, and manipulating PDF documents — PDF with full support for AcroForms, digital signatures (PKCS#12, PKCS#11, PAdES), encryption, a complete annotation hierarchy, tagged PDFs and PDF/UA, PDF/A & PDF/X conformance, portfolios, and document comparison.
DRIT.Pdf is built around a clean-room PDF 1.7/2.0 implementation: the entire stack — object model, parser, writer, filters, font engine, content streams, annotation appearances, and signing ceremony — is implemented in source, with no third-party PDF dependencies.
- What is DRIT.Pdf?
- Features
- Supported File Formats
- Platform Independence
- Get Started
- Conformance & Security
- Repository Contents
- Building
- License
DRIT.Pdf is a pure-managed .NET PDF document library. It does not depend on Adobe Acrobat, on System.Drawing.Common, or on any third-party PDF library. The entire stack — PDF object model, cross-reference parser, writer, decode/encode filters, font engine, content streams, annotation appearance generator, AcroForm model, and digital-signature ceremony — is implemented in source.
Key positioning:
- Clean-room implementation. Written from scratch against the PDF 1.7 and 2.0 ISO specifications. No code copied from PdfSharp, iText, or any other library.
- Full annotation hierarchy. A typed
Annotation→MarkupAnnotationhierarchy with 25+ subtypes (link, line, polyline, text markup, sticky note, stamp, free text, square, circle, ink, caret, redaction, file attachment, popup), each with appearance streams and flatten. - Complete AcroForm model. All field types (text, check box, radio button, dropdown, list box, button, toggle button, signature), fill/read/flatten, FDF/XFDF import/export, form actions, and XFA storage.
- Tagged PDF & accessibility.
TaggedContentstructure tree withStructureElementfor PDF/UA-compliant output. - PDF/A & PDF/X conformance. Write PDF/A-1b, PDF/A-2u, PDF/A-3b, and PDF/X-4 via
SaveOptions.Conformance. - Digital signatures. PKCS#12 (PFX) and PKCS#11 (hardware token) signing, PAdES B-B level, DSS dictionary, LTV support, and signature validation.
- Document comparison.
DocumentComparerwith a typed difference hierarchy for round-trip verification. - Integrated with DRIT.Drawing. Advanced graphics, font support (TrueType, OpenType, CFF, WOFF/WOFF2), and image format coverage.
- Create, load, and save PDF documents from file or stream, with load options (password).
- Merge & split via
Pages.AddClone— document merging and page extraction with resource deduplication. - Incremental update — lightweight
SaveOptions.Incrementaledits without rewriting the file. - Page tree operations with inherited MediaBox/Rotate; page size, rotation, and boundary boxes (Media, Crop, Bleed, Trim, Art).
- Content & drawing:
FormattedTextwith font family, size, weight, style, color;PathContent(lines, Bezier curves, rectangles, stroke/fill, dash patterns);PdfImageplacement;TableDOM with rows, columns, borders, and cell content. - Color spaces: DeviceGray/RGB/CMYK, CalGray/RGB, Lab, ICCBased, Indexed, Separation, DeviceN.
- Patterns & shadings: tiling patterns, shading patterns, axial, radial, free-form/lattice mesh, Coons/tensor patch shadings.
- Text operations: extraction (full document, per page, by region), search (string and regex), replace (global, per page, first occurrence, regex), redaction.
- Annotations: full hierarchy — link, line, polyline, polygon, text markup (highlight, underline, squiggly, strike-out), sticky note, stamp, free text, square, circle, ink, caret, redaction, file attachment, popup — with flags, border style, appearance streams, and flatten.
- Actions: first-class hierarchy —
GoToAction,GoToRemoteAction,LaunchAction,UriAction,JavaScriptAction— on links, form fields, and document open-action. - Forms (AcroForm): all field types, fill/read/flatten, FDF/XFDF import/export, form actions (reset, submit, import/export data), XFA storage.
- Encryption: AES-256, AES-128, RC4 with user/owner passwords and permissions.
- Digital signatures: PKCS#12 (PFX) and PKCS#11 (hardware token), PAdES B-B, DSS dictionary, LTV support, signature validation (hash integrity + certificate chain), signature workflows (author permission, locked fields, timestamp).
- Outlines & navigation: bookmark/outline collection with nested items and destinations, hyperlinks (internal page, external URI, file launch), table of contents.
- Tagged PDF & PDF/UA:
TaggedContentstructure tree withStructureElement(table, row, header, cell, paragraph, note). - Conformance: PDF/A-1b, PDF/A-2u, PDF/A-3b, PDF/X-4 writing.
- Attachments: embedded files (from file/stream with metadata), file attachment annotations, associated files (
/AF), portfolios (folder/field hierarchy, sort levels, collection layout). - Metadata: document info (title, author, subject, keywords, custom properties), XMP metadata read/write.
- Document comparison:
DocumentComparerwith typed difference hierarchy. - Optional content groups (layers) and marked content (tag roles, ActualText).
- Image export (PDF → JPEG/PNG/TIFF) and printing via the separate DRIT.Pdf.Rendering package.
| Format | Read | Write | Specification |
|---|---|---|---|
| ✅ | ✅ | PDF 1.7 / 2.0 (ISO 32000) | |
| PDF/A | ✅ | ✅ | A-1b / A-2u / A-3b (conformance writing) |
| PDF/X-4 | — | ✅ | Printing PDF (conformance writing) |
| FDF | ✅ | ✅ | Forms Data Format |
| XFDF | ✅ | ✅ | XML Forms Data Format |
| JPEG | ✅ | ✅ | Image import / page export |
| PNG | ✅ | ✅ | Image import / page export |
| TIFF | ✅ | ✅ | Image import / page export |
| BMP | ✅ | — | Image import |
| GIF | ✅ | — | Image import |
Image export (PDF → JPEG/PNG/TIFF) and printing are provided by the separate DRIT.Pdf.Rendering package (.NET 8.0 only).
DRIT.Pdf is implemented in pure managed C# and targets net48, net6.0, and net8.0, so it runs on:
- .NET Framework 4.8+
- .NET 6.0 and .NET 8.0
- Windows, Linux, and macOS
Its only dependencies are DRIT.Drawing (graphics and font support), System.Security.Cryptography.Pkcs (.NET 6.0+), and System.Memory (.NET Framework 4.8). No Adobe Acrobat installation, no native libraries, and no third-party PDF packages are required.
The Document class is the entry point for creating, loading, and saving PDFs.
using DRIT.Pdf;
using DRIT.Pdf.Content;
using var document = new Document();
var page = document.Pages.Add();
// Title
using var title = new FormattedText();
title.FontFamily = PdfFontFamily.TimesRoman;
title.FontSize = 24;
title.FontWeight = PdfFontWeight.Bold;
title.Append("Annual Research Report 2025");
page.Content.DrawText(title, new PdfPoint(72, page.Height - 100));
// Body
using var body = new FormattedText();
body.FontFamily = PdfFontFamily.Helvetica;
body.FontSize = 12;
body.MaxTextWidth = 468;
body.Append("This report summarises the research activities of the " +
"Meridian Institute for Applied Science (MIAS) during 2025.");
page.Content.DrawText(body, new PdfPoint(72, page.Height - 140));
document.Save("output.pdf");using DRIT.Pdf;
using DRIT.Pdf.Content;
using var document = Document.Load("input.pdf");
Console.WriteLine($"Pages: {document.Pages.Count}");
Console.WriteLine($"Title: {document.Info.Title ?? "(none)"}");
foreach (var page in document.Pages)
{
Console.WriteLine($"\n-- Page ({page.Width:F0}x{page.Height:F0} pts) --");
foreach (var element in page.Content.Elements.All())
{
switch (element.ElementType)
{
case ContentElementType.Text:
Console.WriteLine($" Text: {element.Bounds}");
break;
case ContentElementType.Image:
var img = (ImageContent)element;
Console.WriteLine($" Image: {img.Image.Size.Width}x{img.Image.Size.Height} px");
break;
case ContentElementType.Path:
Console.WriteLine($" Path bounds: {element.Bounds}");
break;
}
}
}
// Full text via ToString
foreach (var page in document.Pages)
Console.WriteLine(page.Content.ToString());using DRIT.Pdf;
// Merge multiple documents into one
using var merged = new Document();
foreach (var path in new[] { "chapter1.pdf", "chapter2.pdf", "chapter3.pdf" })
{
using var source = Document.Load(path);
merged.Pages.AddClone(source.Pages);
}
merged.Save("merged.pdf");
// Split: extract each page into a separate document
using var toSplit = Document.Load("merged.pdf");
for (int i = 0; i < toSplit.Pages.Count; i++)
{
using var single = new Document();
single.Pages.AddClone(toSplit.Pages[i]);
single.Save($"page_{i + 1}.pdf");
}using DRIT.Pdf;
using DRIT.Pdf.Forms;
using var document = Document.Load("form.pdf");
// Fill a text field by name
document.Form["ParticipantName"].Value = "Sofía Guerrero";
// Tick a check box
var consent = (CheckBoxField)document.Form["ConsentGiven"]!;
consent.IsChecked = true;
// Select a dropdown value
document.Form["Cohort"].Value = "June 2026";
document.Save("filled.pdf");
// Export form data to FDF and re-import
using var fdfStream = new MemoryStream();
document.Form.ExportData(fdfStream, FormDataFormat.Fdf);
fdfStream.Position = 0;
using var blank = Document.Load("form.pdf");
blank.Form.ImportData(fdfStream, FormDataFormat.Fdf);
blank.Save("refilled.pdf");using DRIT.Pdf;
using DRIT.Pdf.Content;
using DRIT.Pdf.Security;
using var document = new Document();
var page = document.Pages.Add();
// Add a visible signature field
var sigField = document.Form.Fields.AddSignature(page, 72, 100, 300, 80);
sigField.Name = "InstructorSignature";
sigField.Appearance.Reason = "Certified by Dr. Petra Holmann";
sigField.Appearance.Location = "TechPath Academy, Berlin";
sigField.Appearance.Icon = SignatureIcon.SignatureAndName;
// Sign with a PFX certificate (PAdES B-B)
var digitalId = new DigitalId("certificate.pfx", "password");
var signer = new Signer(digitalId) { PadesMode = true };
sigField.Sign(signer);
document.Save("signed.pdf");
// Validate on reload
using var loaded = Document.Load("signed.pdf");
var sig = loaded.Form.Fields.SignatureFields[0].Value!;
var result = sig.Validate();
Console.WriteLine($"Signature valid: {result.IsValid}");using DRIT.Pdf;
using DRIT.Pdf.IO;
using DRIT.Pdf.Security;
using var document = new Document();
document.Pages.Add();
var encryption = new PasswordEncryption
{
DocumentOpenPassword = "open-password",
PermissionsPassword = "owner-password",
Permissions = UserAccessPermissions.PrintHighResolution | UserAccessPermissions.FillForm,
EncryptionLevel = EncryptionLevel.Aes256
};
document.SaveOptions.Encryption = encryption;
document.Save("encrypted.pdf");
// Open with the correct password
using var loaded = Document.Load("encrypted.pdf",
new LoadOptions { Password = "open-password" });
Console.WriteLine($"Opened successfully — pages: {loaded.Pages.Count}");using DRIT.Pdf;
using DRIT.Pdf.Content;
using var document = Document.Load("input.pdf");
// Plain-text replacement (correct a typo)
int fixes = document.Pages[0].Content.ReplaceText(
"Meridian Insitute", // typo
"Meridian Institute");
Console.WriteLine($"Typo fixes: {fixes}");
// Case-insensitive replacement
int ci = document.Pages[0].Content.ReplaceText(
"confidential",
"CONFIDENTIAL",
ignoreCase: true);
// Regex replacement (normalize dates DD/MM/YYYY -> YYYY-MM-DD)
int rx = document.Pages[0].Content.ReplaceTextRegex(
@"(\d{2})/(\d{2})/(\d{4})",
"$3-$2-$1");
document.Save("edited.pdf");using DRIT.Pdf;
using DRIT.Pdf.IO;
using DRIT.Pdf.Rendering;
using var document = Document.Load("input.pdf");
// Single-page PNG
document.Save("page1.png",
new ImageSaveOptions(ImageSaveFormat.Png)
{
PageNumber = 0,
PageCount = 1,
Width = 1200,
Dpi = 150
});
// Single-page JPEG
document.Save("page1.jpg",
new ImageSaveOptions(ImageSaveFormat.Jpeg)
{
PageNumber = 0,
PageCount = 1,
Width = 1200,
JpegQuality = 90
});| Capability | Implementation |
|---|---|
| PDF/A-1b writing | SaveOptions.Conformance = ConformanceLevel.PdfA1b |
| PDF/A-2u writing | SaveOptions.Conformance = ConformanceLevel.PdfA2u |
| PDF/A-3b writing | SaveOptions.Conformance = ConformanceLevel.PdfA3b |
| PDF/X-4 writing | SaveOptions.Conformance = ConformanceLevel.PdfX4 |
| AES-256 encryption | PasswordEncryption with EncryptionLevel.Aes256 |
| AES-128 / RC4 encryption | PasswordEncryption with EncryptionLevel.Aes128 / Rc4 |
| PKCS#12 signing | DigitalId(pfxPath, password) + Signer |
| PKCS#11 signing | Pkcs11Module + Pkcs11Token (hardware token via P/Invoke) |
| PAdES B-B | Signer.PadesMode = true (ETSI.CAdES.detached, DSS dictionary, LTV) |
| Signature validation | Signature.Validate() — hash integrity + certificate chain |
| Signature workflows | Author permission, locked fields, timestamp support |
| PDF/UA (tagged PDF) | TaggedContent structure tree with StructureElement |
This repository contains runnable console examples for DRIT.Pdf. The core library is closed-source and distributed via NuGet.
| Example | Description |
|---|---|
GettingStarted |
Create a one-page PDF with title and body text, save, and reload. |
Reading |
Load an existing PDF and iterate content elements (text, images, paths). |
Pages |
Page operations: size, rotation, boundaries. |
MergeAndSplit |
Merge multiple PDFs and split by extracting individual pages. |
Outlines |
Multi-level bookmark tree with page destinations and bookmarks panel. |
Tables |
Styled table with header row, alternating row colors, borders, and column widths. |
Shapes |
Path drawing: lines, Bezier curves, rectangles, stroke/fill. |
HeaderAndFooter |
Text and image in page headers and footers. |
Hyperlinks |
Internal page links and external URI links. |
DocumentProperties |
Built-in info fields, custom properties, and XMP metadata. |
Images |
Insert images into PDF pages. |
EmbeddedFiles |
Attach external files with metadata; write attachments in-process. |
AssociatedFiles |
/AF relationships on pages and content. |
Portfolios |
PDF portfolio with folder/field hierarchy. |
Forms |
Create and fill AcroForm fields; FDF export/import. |
Encryption |
AES-256 encryption with user/owner passwords and permissions. |
DigitalSignature |
PKCS#12 signing with PAdES, visible signature field, and validation. |
TaggedPdf |
Accessibility-tagged PDF (PDF/UA) with structure elements. |
MarkedContent |
Marked-content tags, ActualText, and property dictionaries. |
IncrementalUpdate |
Lightweight incremental save without rewriting the file. |
TextOperations |
Text search, replace (plain, case-insensitive, regex), and removal. |
TextFormatting |
Font family, size, weight, style, color, and max text width. |
ConvertToImage |
PDF to PNG/JPEG/TIFF via DRIT.Pdf.Rendering. |
ConvertFromImage |
Import images to PDF pages. |
Annotations |
Line, polyline, and file attachment annotations; flatten. |
Each example is a standalone console project. Open the individual .csproj in Visual Studio 2022 (17.10+) or build from the command line.
The examples reference the DRIT.Pdf NuGet package. The first public release uses DRIT.Pdf 26.9.1325 and DRIT.Drawing 26.9.1324. Future maintained example revisions may use the rolling 26.* package line, so the repository does not need to be republished for every compatible 26.x package release. A fresh restore can resolve a newer package within that line. When reproducibility matters, use the exact package version recorded in the corresponding GitHub release.
Restore and build a single example:
cd DRIT.Pdf.Examples.Console\GettingStarted
dotnet add package DRIT.Pdf
dotnet run -f net8.0Or build all examples at once (if a solution file is provided):
Get-ChildItem .\DRIT.Pdf.Examples.Console -Recurse -Filter *.csproj | ForEach-Object { dotnet build $_.FullName -f net8.0 -c Release }The examples target net48, net6.0, and net8.0 to match the DRIT.Pdf package. The examples repository is refreshed after approved releases or compatibility-impacting package changes, not necessarily after every product package release. Image export and printing examples additionally require the DRIT.Pdf.Rendering package (.NET 8.0 only):
dotnet add package DRIT.Pdf.RenderingDRIT.Pdf is a closed-source, commercial product of DR-IT Ltd. The examples in this repository are provided for evaluation and learning. See the product page for licensing terms.
Home | Product Page | NuGet