How to Migrate from PdfPig to IronPDF in C#
Migrating from PdfPig to IronPDF expands your PDF capabilities from a reading-focused library (with a narrow writer surface for coordinate-based authoring and basic merging) to a comprehensive PDF solution that handles creation, manipulation, text extraction, and security features. This guide provides a complete, step-by-step migration path that preserves your existing extraction workflows while adding HTML conversion, high-level document manipulation, watermarking, and security authoring that PdfPig does not provide.
Why Migrate from PdfPig to IronPDF
Understanding PdfPig
PdfPig (NuGet package PdfPig, namespace UglyToad.PdfPig) is an open-source .NET PDF reading and extraction library, originally inspired by — and partially ported from — the Apache PDFBox Java project. It allows developers to access the structural content of PDFs with high precision. While PdfPig shines in extraction, its scope is narrower than full-lifecycle commercial libraries. The project remains pre-1.0 (current stable release is 0.1.14), and its README notes that "while the version is below 1.0.0 minor versions will change the public API without warning."
PdfPig provides reliable tools for extracting text (with letter- and word-level positions), images, read-only form data, annotations, and metadata. It also exposes a limited writer surface — PdfDocumentBuilder for low-level new-document authoring and PdfMerger (in UglyToad.PdfPig.Writer) for concatenating existing PDFs. This makes it a suitable choice for applications primarily focused on document analysis, data mining, and basic concatenation.
The Reading-Focused Limitation
PdfPig is reading-first; its writer surface is intentionally narrow. When your application needs to grow beyond extraction and basic merging, PdfPig cannot help:
-
Limited PDF Generation: New documents require manual
PdfPointcoordinate placement viaPdfDocumentBuilder— no high-level layout. -
No HTML-to-PDF: PdfPig is a PDF reading/parsing library, not a PDF generation library. You would need to use a different library for HTML to PDF conversion.
-
Limited Document Manipulation:
PdfMergercovers concatenation, but there is no high-level split/rotate/edit API. -
No Security Authoring: Can read encrypted PDFs (with password) but cannot add passwords, encryption, or digital signatures.
-
No Watermarks/Stamps: No high-level API for visual overlays on existing documents.
- No Form Filling: Forms are read-only — values cannot be changed or added.
PdfPig vs IronPDF Comparison
| Feature | PdfPig | IronPDF |
|---|---|---|
| License | Open Source (Apache 2.0) | Commercial |
| NuGet package | PdfPig (v0.1.14, pre-1.0) |
IronPdf |
| PDF Reading/Extraction | Excellent | Excellent |
| PDF Generation | Limited (coordinate-based via PdfDocumentBuilder) |
Comprehensive |
| HTML to PDF | Not Supported | Supported |
| Text Extraction | Excellent (with word bounding boxes) | Excellent (text only) |
| PDF Merging | Supported (PdfMerger) |
Supported (PdfDocument.Merge) |
| Split / Rotate / Edit | Not supported (high-level) | Supported |
| Watermarks | Not supported | Supported |
| Security/Encryption authoring | Not supported | Supported |
| Support and Documentation | Community Support | Dedicated Support |
| Page Indexing | 1-based | 0-based |
IronPDF supports a complete set of features for creating, reading, editing, and signing PDFs. This versatility allows developers to manage PDF files from start to finish on modern .NET, providing a complete PDF lifecycle solution that extends beyond PdfPig's reading capabilities.
Before You Start
Prerequisites
- .NET Environment: .NET Framework 4.6.2+ or .NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGet Access: Ability to install NuGet packages
- IronPDF License: Obtain your license key from ironpdf.com
NuGet Package Changes
# Remove PdfPig
dotnet remove package PdfPig
# Install IronPDF
dotnet add package IronPdf
# Remove PdfPig
dotnet remove package PdfPig
# Install IronPDF
dotnet add package IronPdf
License Configuration
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Identify PdfPig Usage
# Find PdfPig usage
grep -r "UglyToad\.PdfPig\|PdfDocument\.Open\|GetPages\(\)" --include="*.cs" .
# Find page index references (may need 1→0 conversion)
grep -r "GetPage(\|NumberOfPages" --include="*.cs" .
# Find PdfPig usage
grep -r "UglyToad\.PdfPig\|PdfDocument\.Open\|GetPages\(\)" --include="*.cs" .
# Find page index references (may need 1→0 conversion)
grep -r "GetPage(\|NumberOfPages" --include="*.cs" .
Complete API Reference
Namespace Changes
// Before: PdfPig
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;
// After: IronPDF
using IronPdf;
using IronPdf.Rendering;
// Before: PdfPig
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;
// After: IronPDF
using IronPdf;
using IronPdf.Rendering;
' Before: PdfPig
Imports UglyToad.PdfPig
Imports UglyToad.PdfPig.Content
Imports UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor
' After: IronPDF
Imports IronPdf
Imports IronPdf.Rendering
Document Loading Mappings
| PdfPig | IronPDF |
|---|---|
PdfDocument.Open(path) |
PdfDocument.FromFile(path) |
PdfDocument.Open(bytes) |
PdfDocument.FromBinaryData(bytes) |
PdfDocument.Open(stream) |
PdfDocument.FromStream(stream) |
using (var doc = ...) |
var pdf = ... |
Page Access and Properties Mappings
| PdfPig | IronPDF |
|---|---|
document.NumberOfPages |
pdf.PageCount |
document.GetPages() |
pdf.Pages |
document.GetPage(1) |
pdf.Pages[0] |
Text Extraction Mappings
| PdfPig | IronPDF |
|---|---|
page.Text |
pdf.Pages[i].Text |
page.GetWords() |
pdf.ExtractTextFromPage(i) |
| (manual loop) | pdf.ExtractAllText() |
Metadata Access Mappings
| PdfPig | IronPDF |
|---|---|
document.Information.Title |
pdf.MetaData.Title |
document.Information.Author |
pdf.MetaData.Author |
document.Information.Subject |
pdf.MetaData.Subject |
document.Information.Creator |
pdf.MetaData.Creator |
document.Information.Producer |
pdf.MetaData.Producer |
New Features Not Available in PdfPig
| IronPDF Feature | Description |
|---|---|
renderer.RenderHtmlAsPdf(html) |
HTML to PDF conversion |
renderer.RenderUrlAsPdf(url) |
URL to PDF conversion |
pdf.ApplyWatermark(html) |
Add watermarks |
pdf.SecuritySettings.UserPassword |
Password protection |
pdf.Sign(certificate) |
Digital signatures |
Note: PDF merging is available in both libraries (PdfMerger in PdfPig, PdfDocument.Merge in IronPDF).
Code Migration Examples
Example 1: Text Extraction from PDF
Before (PdfPig):
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
using System.Text;
class Program
{
static void Main()
{
using (var document = PdfDocument.Open("input.pdf"))
{
var text = new StringBuilder();
foreach (var page in document.GetPages())
{
text.AppendLine(page.Text);
}
Console.WriteLine(text.ToString());
}
}
}
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
using System.Text;
class Program
{
static void Main()
{
using (var document = PdfDocument.Open("input.pdf"))
{
var text = new StringBuilder();
foreach (var page in document.GetPages())
{
text.AppendLine(page.Text);
}
Console.WriteLine(text.ToString());
}
}
}
Imports UglyToad.PdfPig
Imports System
Imports System.Text
Class Program
Shared Sub Main()
Using document = PdfDocument.Open("input.pdf")
Dim text = New StringBuilder()
For Each page In document.GetPages()
text.AppendLine(page.Text)
Next
Console.WriteLine(text.ToString())
End Using
End Sub
End Class
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
Dim text As String = pdf.ExtractAllText()
Console.WriteLine(text)
End Sub
End Class
Both PdfPig and IronPDF provide excellent text extraction capabilities. The key difference is in the code pattern. PdfPig requires a using statement with PdfDocument.Open(), manual iteration through pages with GetPages(), and a StringBuilder to accumulate text from each page.Text property.
IronPDF simplifies this to a single call: PdfDocument.FromFile() loads the document, and ExtractAllText() returns all text content at once. No using statement required, no manual iteration, no StringBuilder. See the text extraction documentation for additional options.
Example 2: HTML to PDF Conversion
Before (PdfPig):
PdfPig does not support HTML to PDF conversion. PdfPig is a PDF reading/parsing library, not a PDF generation library. You would need to use a different library for HTML to PDF conversion.
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>")
pdf.SaveAs("output.pdf")
End Sub
End Class
This example highlights the most significant capability gap. PdfPig explicitly states it "does not support HTML to PDF conversion" and "is a PDF reading/parsing library, not a PDF generation library." If you need to create PDFs from HTML with PdfPig, you would need to use a different library entirely.
IronPDF provides native HTML to PDF conversion through ChromePdfRenderer. The RenderHtmlAsPdf() method accepts HTML strings and converts them to PDF documents using a Chromium engine internally for accurate rendering of HTML, CSS, and JavaScript. The resulting PdfDocument can be saved with SaveAs() or manipulated further before saving. See the HTML to PDF documentation for comprehensive examples.
Example 3: Reading PDF Metadata
Before (PdfPig):
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
class Program
{
static void Main()
{
using (var document = PdfDocument.Open("input.pdf"))
{
var info = document.Information;
Console.WriteLine($"Title: {info.Title}");
Console.WriteLine($"Author: {info.Author}");
Console.WriteLine($"Subject: {info.Subject}");
Console.WriteLine($"Creator: {info.Creator}");
Console.WriteLine($"Producer: {info.Producer}");
Console.WriteLine($"Number of Pages: {document.NumberOfPages}");
}
}
}
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
class Program
{
static void Main()
{
using (var document = PdfDocument.Open("input.pdf"))
{
var info = document.Information;
Console.WriteLine($"Title: {info.Title}");
Console.WriteLine($"Author: {info.Author}");
Console.WriteLine($"Subject: {info.Subject}");
Console.WriteLine($"Creator: {info.Creator}");
Console.WriteLine($"Producer: {info.Producer}");
Console.WriteLine($"Number of Pages: {document.NumberOfPages}");
}
}
}
Imports UglyToad.PdfPig
Imports System
Class Program
Shared Sub Main()
Using document = PdfDocument.Open("input.pdf")
Dim info = document.Information
Console.WriteLine($"Title: {info.Title}")
Console.WriteLine($"Author: {info.Author}")
Console.WriteLine($"Subject: {info.Subject}")
Console.WriteLine($"Creator: {info.Creator}")
Console.WriteLine($"Producer: {info.Producer}")
Console.WriteLine($"Number of Pages: {document.NumberOfPages}")
End Using
End Sub
End Class
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
var info = pdf.MetaData;
Console.WriteLine($"Title: {info.Title}");
Console.WriteLine($"Author: {info.Author}");
Console.WriteLine($"Subject: {info.Subject}");
Console.WriteLine($"Creator: {info.Creator}");
Console.WriteLine($"Producer: {info.Producer}");
Console.WriteLine($"Number of Pages: {pdf.PageCount}");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
var info = pdf.MetaData;
Console.WriteLine($"Title: {info.Title}");
Console.WriteLine($"Author: {info.Author}");
Console.WriteLine($"Subject: {info.Subject}");
Console.WriteLine($"Creator: {info.Creator}");
Console.WriteLine($"Producer: {info.Producer}");
Console.WriteLine($"Number of Pages: {pdf.PageCount}");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
Dim info = pdf.MetaData
Console.WriteLine($"Title: {info.Title}")
Console.WriteLine($"Author: {info.Author}")
Console.WriteLine($"Subject: {info.Subject}")
Console.WriteLine($"Creator: {info.Creator}")
Console.WriteLine($"Producer: {info.Producer}")
Console.WriteLine($"Number of Pages: {pdf.PageCount}")
End Sub
End Class
Both libraries provide metadata access with nearly identical patterns. PdfPig accesses metadata through document.Information and page count through document.NumberOfPages. IronPDF uses pdf.MetaData for metadata and pdf.PageCount for page count.
The migration is straightforward: replace PdfDocument.Open() with PdfDocument.FromFile(), document.Information with pdf.MetaData, and document.NumberOfPages with pdf.PageCount. Remove the using statement wrapper since IronPDF doesn't require it.
Critical Migration Notes
Page Indexing Change
PdfPig uses 1-based indexing; IronPDF uses 0-based:
// PdfPig: 1-based indexing
var firstPage = document.GetPage(1); // First page
// IronPDF: 0-based indexing
var firstPage = pdf.Pages[0]; // First page
// Migration helper
int pdfPigIndex = 1;
int ironPdfIndex = pdfPigIndex - 1;
// PdfPig: 1-based indexing
var firstPage = document.GetPage(1); // First page
// IronPDF: 0-based indexing
var firstPage = pdf.Pages[0]; // First page
// Migration helper
int pdfPigIndex = 1;
int ironPdfIndex = pdfPigIndex - 1;
' PdfPig: 1-based indexing
Dim firstPage = document.GetPage(1) ' First page
' IronPDF: 0-based indexing
Dim firstPage = pdf.Pages(0) ' First page
' Migration helper
Dim pdfPigIndex As Integer = 1
Dim ironPdfIndex As Integer = pdfPigIndex - 1
Using Statement Not Required
// PdfPig: Requires using for disposal
using (var document = PdfDocument.Open("input.pdf"))
{
// ...
}
// IronPDF: No using required (but can use for cleanup)
var pdf = PdfDocument.FromFile("input.pdf");
// ...
// pdf.Dispose(); // Optional
// PdfPig: Requires using for disposal
using (var document = PdfDocument.Open("input.pdf"))
{
// ...
}
// IronPDF: No using required (but can use for cleanup)
var pdf = PdfDocument.FromFile("input.pdf");
// ...
// pdf.Dispose(); // Optional
Imports PdfPig
Imports IronPDF
Using document = PdfDocument.Open("input.pdf")
' ...
End Using
Dim pdf = PdfDocument.FromFile("input.pdf")
' ...
' pdf.Dispose() ' Optional
Document Loading Change
// PdfPig: PdfDocument.Open()
using (var document = PdfDocument.Open("input.pdf"))
// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("input.pdf");
// PdfPig: PdfDocument.Open()
using (var document = PdfDocument.Open("input.pdf"))
// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("input.pdf");
Imports PdfPig
Imports IronPDF
Using document = PdfDocument.Open("input.pdf")
End Using
Dim pdf = PdfDocument.FromFile("input.pdf")
Metadata Property Name Change
// PdfPig: document.Information
var info = document.Information;
// IronPDF: pdf.MetaData
var info = pdf.MetaData;
// PdfPig: document.Information
var info = document.Information;
// IronPDF: pdf.MetaData
var info = pdf.MetaData;
' PdfPig: document.Information
Dim info = document.Information
' IronPDF: pdf.MetaData
Dim info = pdf.MetaData
Page Count Property Change
// PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}");
// IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}");
// PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}");
// IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}");
' PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}")
' IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}")
New Capabilities After Migration
After migrating to IronPDF, you gain capabilities that PdfPig cannot provide:
PDF Merging
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
Watermarks
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>")
Password Protection
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.UserPassword = "userpassword"
pdf.SecuritySettings.OwnerPassword = "ownerpassword"
Digital Signatures
var signature = new PdfSignature("certificate.pfx", "password")
{
SigningContact = "support@company.com",
SigningReason = "Document Approval"
};
pdf.Sign(signature);
var signature = new PdfSignature("certificate.pfx", "password")
{
SigningContact = "support@company.com",
SigningReason = "Document Approval"
};
pdf.Sign(signature);
Dim signature As New PdfSignature("certificate.pfx", "password") With {
.SigningContact = "support@company.com",
.SigningReason = "Document Approval"
}
pdf.Sign(signature)
Feature Comparison Summary
| Feature | PdfPig | IronPDF |
|---|---|---|
| Text Extraction | ✓ | ✓ |
| Metadata Access | ✓ | ✓ |
| Image Extraction | ✓ | ✓ |
| PDF Creation | Limited (coordinate-based) | ✓ |
| HTML to PDF | ✗ | ✓ |
| URL to PDF | ✗ | ✓ |
| Merge PDFs | ✓ (PdfMerger) |
✓ |
| Split PDFs | ✗ | ✓ |
| Watermarks | ✗ | ✓ |
| Form Filling | ✗ | ✓ |
| Password Protection | ✗ | ✓ |
| Digital Signatures | ✗ | ✓ |
| Word Position Data | ✓ | ✗ |
Migration Checklist
Pre-Migration
- Inventory all PdfPig usage in codebase
- Identify if you need word-level position data (consider hybrid approach)
- Note all page index references (need to convert 1-based to 0-based)
- Plan IronPDF license key storage (environment variables recommended)
- Test with IronPDF trial license first
Package Changes
- Remove
PdfPigNuGet package:dotnet remove package PdfPig - Install
IronPdfNuGet package:dotnet add package IronPdf
Code Changes
- Update namespace imports (
using UglyToad.PdfPig;→using IronPdf;) - Replace
PdfDocument.Open()withPdfDocument.FromFile() - Replace
document.Informationwithpdf.MetaData - Replace
document.NumberOfPageswithpdf.PageCount - Convert page indices from 1-based to 0-based
- Remove
usingstatements (optional, IronPDF doesn't require them) - Add IronPDF license key at application startup
Post-Migration
- Test text extraction output matches expectations
- Test all PDF generation scenarios
- Add new capabilities (merging, watermarks, security) as needed
- Install Linux dependencies if deploying to Linux

