Skip to footer content
MIGRATION GUIDES

How to Migrate from Pdfium to IronPDF in C#

Migrating from Pdfium.NET to IronPDF moves your .NET PDF workflow from a rendering-focused library with native binary dependencies to a comprehensive PDF solution that handles creation, manipulation, and rendering without platform-specific complexity. This guide provides a complete, step-by-step migration path that eliminates native dependency management while adding capabilities that Pdfium cannot provide.

Why Migrate from Pdfium to IronPDF

Understanding Pdfium.NET

Pdfium.NET is a .NET wrapper for Google's PDFium library, renowned for its efficiency and speed in rendering PDF documents. It has emerged as a significant library for developers delving into the intricacies of PDF rendering within C# applications, providing high-fidelity replication of PDF content in .NET environments.

However, despite its prowess in rendering, Pdfium.NET's capabilities for creating and manipulating PDF documents are limited. It's mainly built for applications that require displaying PDF content accurately with less emphasis on modifying or creating new PDFs.

Critical Pdfium Limitations

  1. Rendering-Only Focus: Cannot create PDFs from HTML, images, or programmatically. Pdfium's capabilities are restricted to viewing and rendering PDFs.

  2. No PDF Manipulation: Cannot merge, split, or modify PDF content. PDF merging is not natively supported—you would need to use another library like iTextSharp or PdfSharp.

  3. Native Binary Dependencies: Requires platform-specific PDFium binaries. Developers need to manage native PDFium binaries, an aspect that adds complexity during deployment and distribution.

  4. Deployment Complexity: Must bundle and manage native DLLs per platform with x86, x64, and runtimes folders.

  5. Limited Text Extraction: Basic text extraction without formatting. Text extraction requires additional work with Pdfium.NET.

  6. No HTML to PDF: Cannot convert web content to PDF. HTML to PDF conversion is not natively supported in Pdfium.NET.

  7. No Headers/Footers: Cannot add page numbers or repeating content.

  8. No Watermarks: Cannot stamp documents with overlays.

  9. No Form Support: Cannot fill or read PDF forms.

  10. No Security Features: Cannot encrypt or password-protect PDFs.

Pdfium vs IronPDF Comparison

AspectPdfium.NETIronPDF
Primary FocusRendering/viewingComplete PDF solution
Rendering FidelityHigh-fidelity renderingHigh, especially for HTML/CSS/JS
PDF Creation✓ (HTML, URL, images)
PDF Manipulation✓ (merge, split, edit)
HTML to PDF✓ (Chromium engine)
Watermarks
Headers/Footers
Form Filling
Security
Native DependenciesRequiredNone (fully managed)
Cross-PlatformComplex setupAutomatic
Ease of DeploymentComplicated by native dependenciesEasier; less dependency complication

For teams planning .NET 10 and C# 14 adoption through 2025 and 2026, IronPDF provides a fully managed foundation that eliminates native binary management while adding comprehensive PDF creation and manipulation 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

# Remove Pdfium packages
dotnet remove package Pdfium.NET
dotnet remove package Pdfium.Net.SDK
dotnet remove package PdfiumViewer

# Install IronPDF
dotnet add package IronPdf
# Remove Pdfium packages
dotnet remove package Pdfium.NET
dotnet remove package Pdfium.Net.SDK
dotnet remove package PdfiumViewer

# Install IronPDF
dotnet add package IronPdf
SHELL

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";
$vbLabelText   $csharpLabel

Identify Pdfium Usage

# Find Pdfium usage
grep -r "Pdfium\|PdfDocument\.Load\|\.Render\(" --include="*.cs" .

# Find native binary references
grep -r "pdfium\.dll\|pdfium\.so\|pdfium\.dylib" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -r "#if.*64\|WIN32\|WIN64\|LINUX\|OSX" --include="*.cs" .
# Find Pdfium usage
grep -r "Pdfium\|PdfDocument\.Load\|\.Render\(" --include="*.cs" .

# Find native binary references
grep -r "pdfium\.dll\|pdfium\.so\|pdfium\.dylib" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -r "#if.*64\|WIN32\|WIN64\|LINUX\|OSX" --include="*.cs" .
SHELL

Complete API Reference

Namespace Changes

// Pdfium.NET
using Pdfium;
using Pdfium.Net;
using PdfiumViewer;

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// Pdfium.NET
using Pdfium;
using Pdfium.Net;
using PdfiumViewer;

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
$vbLabelText   $csharpLabel

Core Class Mappings

Pdfium.NETIronPDFNotes
PdfDocumentPdfDocumentSame name, different capabilities
PdfPagePdfPageSimilar interface
PdfPageCollectionPdfPageCollectionSimilar interface
(not available)ChromePdfRendererPDF creation
(not available)HtmlHeaderFooterHeaders/footers

Document Loading Mappings

Pdfium.NETIronPDFNotes
PdfDocument.Load(path)PdfDocument.FromFile(path)Load from file
PdfDocument.Load(stream)PdfDocument.FromStream(stream)Load from stream
PdfDocument.Load(bytes)PdfDocument.FromBinaryData(bytes)Load from bytes
new PdfDocument(path)PdfDocument.FromFile(path)Constructor pattern

Document Properties Mappings

Pdfium.NETIronPDFNotes
document.PageCountdocument.PageCountSame
document.Pagesdocument.PagesSimilar collection
document.Pages[index]document.Pages[index]Zero-based
document.GetPageSize(index)document.Pages[index].Width/HeightDirect properties

Text Extraction Mappings

Pdfium.NETIronPDFNotes
document.GetPdfText(pageIndex)document.Pages[index].TextPer-page
(manual loop)document.ExtractAllText()All pages at once
page.GetTextBounds()page.TextSimplified

Saving Documents Mappings

Pdfium.NETIronPDFNotes
document.Save(path)document.SaveAs(path)Different method name
document.Save(stream)document.StreamAccess stream
(not available)document.BinaryDataGet bytes

Page Rendering Mappings

Pdfium.NETIronPDFNotes
page.Render(width, height)pdf.RasterizeToImageFiles(path, dpi)Rasterize
page.Render(width, height, flags)DPI parameterQuality control
document.Render(index, width, height)pdf.RasterizeToImageFiles()Batch render
page.RenderToScale(scale)DPI: 72 * scaleScale to DPI conversion

New Features Not Available in Pdfium

IronPDF FeatureDescription
ChromePdfRenderer.RenderHtmlAsPdf()Create from HTML
ChromePdfRenderer.RenderUrlAsPdf()Create from URL
ChromePdfRenderer.RenderHtmlFileAsPdf()Create from HTML file
PdfDocument.Merge()Combine PDFs
pdf.CopyPages()Extract pages
pdf.RemovePages()Delete pages
pdf.InsertPdf()Insert PDF at position
pdf.ApplyWatermark()Add watermarks
pdf.AddHtmlHeaders()Add headers
pdf.AddHtmlFooters()Add footers
pdf.SecuritySettingsPassword protection
pdf.SignWithDigitalSignature()Digital signatures
pdf.FormForm filling

Code Migration Examples

Example 1: Text Extraction from PDF

Before (Pdfium):

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // Note: PdfiumViewer has limited text extraction capabilities
                // Text extraction requires additional work with Pdfium.NET
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // Note: PdfiumViewer has limited text extraction capabilities
                // Text extraction requires additional work with Pdfium.NET
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
$vbLabelText   $csharpLabel

The difference here is significant. Pdfium requires a manual loop through each page with GetPdfText(pageIndex), building a StringBuilder and managing the using statement for proper disposal. The code notes that "PdfiumViewer has limited text extraction capabilities" and "text extraction requires additional work."

IronPDF simplifies this to three lines: load with PdfDocument.FromFile(), extract with ExtractAllText(), and output. The ExtractAllText() method handles all pages automatically with more advanced text extraction capabilities. If you need per-page extraction, you can use pdf.Pages[index].Text. See the text extraction documentation for additional options.

Example 2: PDF Merging

Before (Pdfium):

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

// Note: PdfiumViewer does not have native PDF merging functionality
// You would need to use additional libraries or implement custom logic
class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        // PdfiumViewer is primarily for rendering/viewing
        // PDF merging is not natively supported
        // You would need to use another library like iTextSharp or PdfSharp

        Console.WriteLine("PDF merging not natively supported in PdfiumViewer");
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

// Note: PdfiumViewer does not have native PDF merging functionality
// You would need to use additional libraries or implement custom logic
class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        // PdfiumViewer is primarily for rendering/viewing
        // PDF merging is not natively supported
        // You would need to use another library like iTextSharp or PdfSharp

        Console.WriteLine("PDF merging not natively supported in PdfiumViewer");
    }
}
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        var pdf = PdfDocument.Merge(pdfFiles);
        pdf.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        var pdf = PdfDocument.Merge(pdfFiles);
        pdf.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
$vbLabelText   $csharpLabel

This example highlights a fundamental capability gap. Pdfium cannot merge PDFs—the code explicitly states "PDF merging is not natively supported in PdfiumViewer" and "You would need to use another library like iTextSharp or PdfSharp."

IronPDF provides native merging with the static PdfDocument.Merge() method that accepts a list of file paths directly. The result is a new PdfDocument that you save with SaveAs(). Learn more about merging and splitting PDFs.

Example 3: HTML to PDF Conversion

Before (Pdfium):

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System.IO;
using System.Drawing.Printing;

// Note: PdfiumViewer is primarily for viewing/rendering PDFs, not creating them from HTML
// For HTML to PDF with Pdfium.NET, you would need additional libraries
// This example shows a limitation of Pdfium.NET
class Program
{
    static void Main()
    {
        // Pdfium.NET does not have native HTML to PDF conversion
        // You would need to use a separate library to convert HTML to PDF
        // then use Pdfium for manipulation
        string htmlContent = "<h1>Hello World</h1>";

        // This functionality is not directly available in Pdfium.NET
        Console.WriteLine("HTML to PDF conversion not natively supported in Pdfium.NET");
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System.IO;
using System.Drawing.Printing;

// Note: PdfiumViewer is primarily for viewing/rendering PDFs, not creating them from HTML
// For HTML to PDF with Pdfium.NET, you would need additional libraries
// This example shows a limitation of Pdfium.NET
class Program
{
    static void Main()
    {
        // Pdfium.NET does not have native HTML to PDF conversion
        // You would need to use a separate library to convert HTML to PDF
        // then use Pdfium for manipulation
        string htmlContent = "<h1>Hello World</h1>";

        // This functionality is not directly available in Pdfium.NET
        Console.WriteLine("HTML to PDF conversion not natively supported in Pdfium.NET");
    }
}
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
$vbLabelText   $csharpLabel

This example demonstrates the most significant capability difference. Pdfium explicitly states "HTML to PDF conversion not natively supported in Pdfium.NET" and "You would need to use a separate library to convert HTML to PDF."

IronPDF provides native HTML to PDF conversion through ChromePdfRenderer, which uses a Chromium engine internally for accurate rendering of HTML, CSS, and JavaScript. The RenderHtmlAsPdf() method converts HTML strings directly to PDF documents. IronPDF can also render URLs with RenderUrlAsPdf() and HTML files with RenderHtmlFileAsPdf(). See the HTML to PDF documentation for comprehensive examples.


Native Dependency Removal

One of the most significant benefits of migrating from Pdfium to IronPDF is eliminating native binary management.

Before (Pdfium) - Complex Deployment

MyApp/
├── bin/
│   ├── MyApp.dll
│   ├── Pdfium.NET.dll
│   ├── x86/
│   │   └── pdfium.dll
│   └── x64/
│       └── pdfium.dll
├── runtimes/
│   ├── win-x86/native/
│   │   └── pdfium.dll
│   └── win-x64/native/
│       └── pdfium.dll

After (IronPDF) - Clean Deployment

MyApp/
├── bin/
│   ├── MyApp.dll
│   └── IronPdf.dll  # Everything included

Remove Native Binary References

# Delete native PDFium binaries
rm -rf x86/ x64/ runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
# Delete native PDFium binaries
rm -rf x86/ x64/ runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
SHELL

Critical Migration Notes

Scale to DPI Conversion

Pdfium uses scale factors; IronPDF uses DPI:

// Formula: IronPDF DPI = 72 × Pdfium scale
// Pdfium scale 2.0 → IronPDF DPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
// Formula: IronPDF DPI = 72 × Pdfium scale
// Pdfium scale 2.0 → IronPDF DPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
$vbLabelText   $csharpLabel

Document Loading Method Change

// Pdfium
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
// Pdfium
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
$vbLabelText   $csharpLabel

Save Method Change

// Pdfium
document.Save(path)

// IronPDF
pdf.SaveAs(path)
// Pdfium
document.Save(path)

// IronPDF
pdf.SaveAs(path)
$vbLabelText   $csharpLabel

Disposal Pattern Simplification

// Pdfium: Required explicit disposal
using (var document = PdfDocument.Load(path))
using (var page = document.Pages[0])
using (var bitmap = page.Render(1024, 768))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
// Pdfium: Required explicit disposal
using (var document = PdfDocument.Load(path))
using (var page = document.Pages[0])
using (var bitmap = page.Render(1024, 768))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
$vbLabelText   $csharpLabel

Platform-Specific Code Removal

// Pdfium: Required platform detection
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
// Pdfium: Required platform detection
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
$vbLabelText   $csharpLabel

Feature Comparison Summary

FeaturePdfium.NETIronPDF
Load PDF
Render to Image
Extract Text✓ (basic)✓ (advanced)
Page Info
Create from HTML
Create from URL
Merge PDFs
Split PDFs
Add Watermarks
Headers/Footers
Form Filling
Digital Signatures
Password Protection
Native DependenciesRequiredNone
Cross-PlatformComplexAutomatic
Memory ManagementManual disposalSimplified

Migration Checklist

Pre-Migration

  • Identify all Pdfium usage in codebase
  • Document current rendering dimensions/scales used
  • List native binary locations in project
  • Check for platform-specific loading code
  • Identify PDF creation needs (currently using separate tools?)
  • Review disposal patterns for conversion
  • Obtain IronPDF license key

Package Changes

  • Remove Pdfium.NET, Pdfium.Net.SDK, PdfiumViewer NuGet packages
  • Delete native pdfium.dll binaries from x86/, x64/, runtimes/ folders
  • Remove platform-specific conditional compilation
  • Update .csproj to remove native binary references
  • Install IronPdf NuGet package: dotnet add package IronPdf

Code Changes

  • Add license key configuration at startup
  • Replace PdfDocument.Load() with PdfDocument.FromFile()
  • Replace document.Save() with pdf.SaveAs()
  • Replace document.GetPdfText(i) loops with pdf.ExtractAllText()
  • Convert scale factors to DPI values (DPI = 72 × scale)
  • Simplify disposal patterns (remove nested using statements)
  • Remove platform-specific code

Post-Migration

  • Test rendering output quality
  • Compare text extraction results
  • Test cross-platform deployment
  • Add new capabilities (HTML to PDF, merging, watermarks, security)
  • Update documentation

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More