Migrate from PdfPig to IronPDF

IronPDF in C#Photo from Unsplash

Originally Posted On: https://ironpdf.com/blog/migration-guides/migrate-from-pdfpig-to-ironpdf/

How to Migrate from PdfPig to IronPDF in C#

Migrating from PdfPig to IronPDF expands your PDF capabilities from a reading-only library 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 PDF generation, HTML conversion, document manipulation, and security capabilities that PdfPig cannot provide.

Why Migrate from PdfPig to IronPDF

Understanding PdfPig

PdfPig is an open-source PDF reading and extraction library specifically designed for C#. As an arm of the reputable Apache PDFBox project, this library allows developers to access the content of PDFs with remarkable precision. While PdfPig shines in extraction capabilities, its scope is largely limited compared to more comprehensive libraries available on the market.

PdfPig provides developers with reliable tools for extracting text, images, form data, and metadata from PDF files. This makes it a suitable choice for applications primarily focused on document analysis and data mining. However, PdfPig’s capabilities are fundamentally limited to parsing existing documents.

The Reading-Only Limitation

PdfPig focuses exclusively on PDF reading. When your application needs to grow beyond extraction, PdfPig cannot help:

  1. No PDF Generation: Cannot create PDFs from HTML, URLs, or programmatically.
  2. 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.
  3. No Document Manipulation: Cannot merge, split, or modify PDFs.
  4. No Security Features: Cannot add passwords, encryption, or digital signatures.
  5. No Watermarks/Stamps: Cannot add visual overlays to existing documents.
  6. No Form Filling: Cannot programmatically fill PDF forms.

PdfPig vs IronPDF Comparison

Feature PdfPig IronPDF
License Open Source (Apache 2.0) Commercial
PDF Reading/Extraction Excellent Excellent
PDF Generation Limited Comprehensive
HTML to PDF Not Supported Supported
Text Extraction Excellent Excellent
PDF Manipulation Not supported Merge, split, rotate
Watermarks Not supported Full support
Security/Encryption Not supported Full support
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. For teams planning .NET 10 and C# 14 adoption through 2025 and 2026, IronPDF provides a complete PDF lifecycle solution that extends beyond PdfPig’s reading capabilities.

 

Before You Start

Prerequisites

  1. .NET Environment: .NET Framework 4.6.2+ or .NET Core 3.1+ / .NET 5/6/7/8/9+
  2. NuGet Access: Ability to install NuGet packages
  3. IronPDF License: Obtain your license key from ironpdf.com

NuGet Package Changes

  1. # Remove PdfPig
  2. dotnet remove package PdfPig
  3. # Install IronPDF
  4. dotnet add package IronPdf
SHELL

License Configuration

  1. // Add at application startup (Program.cs or Startup.cs)
  2. IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

Identify PdfPig Usage

  1. # Find PdfPig usage
  2. grep -r "UglyToad.PdfPig|PdfDocument.Open|GetPages()" --include="*.cs" .
  3. # Find page index references (may need 1→0 conversion)
  4. grep -r "GetPage(|NumberOfPages" --include="*.cs" .
SHELL

Complete API Reference

Namespace Changes

  1. // Before: PdfPig
  2. using UglyToad.PdfPig;
  3. using UglyToad.PdfPig.Content;
  4. using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;
  5. // After: IronPDF
  6. using IronPdf;
  7. using IronPdf.Rendering;

Document Loading Mappings

PdfPig IronPDF Notes
PdfDocument.Open(path) PdfDocument.FromFile(path) Load from file
PdfDocument.Open(bytes) PdfDocument.FromBinaryData(bytes) Load from bytes
PdfDocument.Open(stream) PdfDocument.FromStream(stream) Load from stream
using (var doc = ...) var pdf = ... IronPDF doesn’t require using

Page Access and Properties Mappings

PdfPig IronPDF Notes
document.NumberOfPages pdf.PageCount Total page count
document.GetPages() pdf.Pages Page collection
document.GetPage(1) pdf.Pages[0] Single page (note: 1-based vs 0-based)

Text Extraction Mappings

PdfPig IronPDF Notes
page.Text pdf.Pages[i].Text Page text
page.GetWords() pdf.ExtractTextFromPage(i) Words/text from page
(manual loop) pdf.ExtractAllText() All text at once

Metadata Access Mappings

PdfPig IronPDF Notes
document.Information.Title pdf.MetaData.Title Document title
document.Information.Author pdf.MetaData.Author Author
document.Information.Subject pdf.MetaData.Subject Subject
document.Information.Creator pdf.MetaData.Creator Creator
document.Information.Producer pdf.MetaData.Producer Producer

New Features Not Available in PdfPig

IronPDF Feature Description
renderer.RenderHtmlAsPdf(html) HTML to PDF conversion
renderer.RenderUrlAsPdf(url) URL to PDF conversion
PdfDocument.Merge(pdfs) Merge multiple PDFs
pdf.ApplyWatermark(html) Add watermarks
pdf.SecuritySettings.UserPassword Password protection
pdf.Sign(certificate) Digital signatures

 

Code Migration Examples

Example 1: Text Extraction from PDF

Before (PdfPig):

  1. // NuGet: Install-Package PdfPig
  2. using UglyToad.PdfPig;
  3. using System;
  4. using System.Text;
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. using (var document = PdfDocument.Open("input.pdf"))
  10. {
  11. var text = new StringBuilder();
  12. foreach (var page in document.GetPages())
  13. {
  14. text.AppendLine(page.Text);
  15. }
  16. Console.WriteLine(text.ToString());
  17. }
  18. }
  19. }

After (IronPDF):

  1. // NuGet: Install-Package IronPdf
  2. using IronPdf;
  3. using System;
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. var pdf = PdfDocument.FromFile("input.pdf");
  9. string text = pdf.ExtractAllText();
  10. Console.WriteLine(text);
  11. }
  12. }

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):

  1. // PdfPig does not support HTML to PDF conversion
  2. // PdfPig is a PDF reading/parsing library, not a PDF generation library
  3. // You would need to use a different library for HTML to PDF conversion

After (IronPDF):

  1. // NuGet: Install-Package IronPdf
  2. using IronPdf;
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. var renderer = new ChromePdfRenderer();
  8. var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
  9. pdf.SaveAs("output.pdf");
  10. }
  11. }

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):

  1. // NuGet: Install-Package PdfPig
  2. using UglyToad.PdfPig;
  3. using System;
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. using (var document = PdfDocument.Open("input.pdf"))
  9. {
  10. var info = document.Information;
  11. Console.WriteLine($"Title: {info.Title}");
  12. Console.WriteLine($"Author: {info.Author}");
  13. Console.WriteLine($"Subject: {info.Subject}");
  14. Console.WriteLine($"Creator: {info.Creator}");
  15. Console.WriteLine($"Producer: {info.Producer}");
  16. Console.WriteLine($"Number of Pages: {document.NumberOfPages}");
  17. }
  18. }
  19. }

After (IronPDF):

  1. // NuGet: Install-Package IronPdf
  2. using IronPdf;
  3. using System;
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. var pdf = PdfDocument.FromFile("input.pdf");
  9. var info = pdf.MetaData;
  10. Console.WriteLine($"Title: {info.Title}");
  11. Console.WriteLine($"Author: {info.Author}");
  12. Console.WriteLine($"Subject: {info.Subject}");
  13. Console.WriteLine($"Creator: {info.Creator}");
  14. Console.WriteLine($"Producer: {info.Producer}");
  15. Console.WriteLine($"Number of Pages: {pdf.PageCount}");
  16. }
  17. }

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:

  1. // PdfPig: 1-based indexing
  2. var firstPage = document.GetPage(1); // First page
  3. // IronPDF: 0-based indexing
  4. var firstPage = pdf.Pages[0]; // First page
  5. // Migration helper
  6. int pdfPigIndex = 1;
  7. int ironPdfIndex = pdfPigIndex - 1;

Using Statement Not Required

  1. // PdfPig: Requires using for disposal
  2. using (var document = PdfDocument.Open("input.pdf"))
  3. {
  4. // ...
  5. }
  6. // IronPDF: No using required (but can use for cleanup)
  7. var pdf = PdfDocument.FromFile("input.pdf");
  8. // ...
  9. // pdf.Dispose(); // Optional

Document Loading Change

  1. // PdfPig: PdfDocument.Open()
  2. using (var document = PdfDocument.Open("input.pdf"))
  3. // IronPDF: PdfDocument.FromFile()
  4. var pdf = PdfDocument.FromFile("input.pdf");

Metadata Property Name Change

  1. // PdfPig: document.Information
  2. var info = document.Information;
  3. // IronPDF: pdf.MetaData
  4. var info = pdf.MetaData;

Page Count Property Change

  1. // PdfPig: document.NumberOfPages
  2. Console.WriteLine($"Pages: {document.NumberOfPages}");
  3. // IronPDF: pdf.PageCount
  4. Console.WriteLine($"Pages: {pdf.PageCount}");

New Capabilities After Migration

After migrating to IronPDF, you gain capabilities that PdfPig cannot provide:

PDF Merging

  1. var pdf1 = PdfDocument.FromFile("document1.pdf");
  2. var pdf2 = PdfDocument.FromFile("document2.pdf");
  3. var merged = PdfDocument.Merge(pdf1, pdf2);
  4. merged.SaveAs("merged.pdf");

Watermarks

  1. pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");

Password Protection

  1. pdf.SecuritySettings.UserPassword = "userpassword";
  2. pdf.SecuritySettings.OwnerPassword = "ownerpassword";

Digital Signatures

  1. var signature = new PdfSignature("certificate.pfx", "password")
  2. {
  3. SigningContact = "support@company.com",
  4. SigningReason = "Document Approval"
  5. };
  6. pdf.Sign(signature);

Feature Comparison Summary

Feature PdfPig IronPDF
Text Extraction
Metadata Access
Image Extraction
PDF Creation Limited
HTML to PDF
URL to PDF
Merge PDFs
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 PdfPig NuGet package: dotnet remove package PdfPig
  • Install IronPdf NuGet package: dotnet add package IronPdf

Code Changes

  • Update namespace imports (using UglyToad.PdfPig;using IronPdf;)
  • Replace PdfDocument.Open() with PdfDocument.FromFile()
  • Replace document.Information with pdf.MetaData
  • Replace document.NumberOfPages with pdf.PageCount
  • Convert page indices from 1-based to 0-based
  • Remove using statements (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