Skip to footer content
MIGRATION GUIDES

Migrate from Foxit PDF SDK to IronPDF: (.NET Guide)

Migrating from Foxit PDF SDK to IronPDF simplifies your .NET PDF generation workflow by replacing complex enterprise-focused APIs with modern, developer-friendly patterns. This guide provides a full, step-by-step migration path that removes unnecessary code and makes PDF operations easier across your codebase.

Why Migrate from Foxit PDF SDK to IronPDF

The Foxit PDF Challenges

Foxit PDF SDK is a strong enterprise-level library, but it comes with significant complexity that can slow down development:

  1. Complex Licensing System: Multiple products, SKUs, and license types (per-developer, per-server, OEM, etc.) make it difficult to choose the right option for your project.

  2. Enterprise Pricing: Pricing is tailored for large organizations and can be prohibitive for smaller teams or individual developers.

  3. Heavy Native Package: The public NuGet package (Foxit.SDK.Dotnet) is large (~240 MB), and older projects may still carry direct DLL references or private feed configurations.

  4. Verbose API: Library initialization with Library.Initialize(), error code checking, and explicit Library.Release() calls add boilerplate to every operation.

  5. Separate HTML2PDF Engine: HTML to PDF conversion requires the HTML2PDF engine binaries, distributed separately from Foxit support/sales rather than bundled in the NuGet package.

  6. Complex Configuration: Settings require detailed object configuration (e.g., HTML2PDFSettingData) with multiple properties.

  7. C++ Heritage: API patterns reflect C++ origins, feeling less natural in modern C# applications.

Foxit PDF vs IronPDF Comparison

Aspect Foxit PDF SDK IronPDF
Installation Foxit.SDK.Dotnet (~240 MB) + separate HTML2PDF engine Simple NuGet package
Licensing Sales-led, per-developer per-platform Transparent, suitable for all sizes
Initialization Library.Initialize(sn, key) Set license key once
Error Handling ErrorCode enums Standard .NET exceptions
HTML to PDF Separate engine download Built-in Chromium engine
API Style C++ heritage, verbose Modern .NET patterns
Resource Cleanup Manual Close()/Release() IDisposable/automatic
Documentation Enterprise docs portal Public tutorials

Cost-Benefit Analysis

Moving from Foxit PDF to IronPDF offers tangible development benefits: reduced complexity through simpler APIs, faster development with intuitive methods, modern .NET compatibility including async/await and LINQ support, an HTML-first approach that uses existing web skills, and HTML conversion included without a separate engine download. IronPDF runs on current .NET versions and pairs cleanly with modern C# patterns.


Before You Start

Prerequisites

  1. .NET Environment: IronPDF supports .NET Framework 4.6.2+, .NET Core 3.1+, .NET 5/6/7/8/9+
  2. NuGet Access: Ensure you can install packages from NuGet
  3. License Key: Obtain your IronPDF license key for production use from ironpdf.com

Backup Your Project

# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup before Foxit PDF SDK to IronPDF migration"
# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup before Foxit PDF SDK to IronPDF migration"
SHELL

Identify All Foxit PDF Usage

# Find all Foxit PDF SDK references
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .

# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"
# Find all Foxit PDF SDK references
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .

# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"
SHELL

Document Current Functionality

Before migration, catalog:

  • Which Foxit PDF features you use (HTML conversion, annotations, forms, security)
  • License key locations and initialization code
  • Custom configurations and settings
  • Error handling patterns using ErrorCode enums

Quick Start Migration

Step 1: Update NuGet Packages

# Remove the Foxit NuGet package
dotnet remove package Foxit.SDK.Dotnet

# Install IronPDF
dotnet add package IronPdf
# Remove the Foxit NuGet package
dotnet remove package Foxit.SDK.Dotnet

# Install IronPDF
dotnet add package IronPdf
SHELL

If you have older direct Foxit DLL references in .csproj (older builds), remove them manually:


<Reference Include="fsdk_dotnet">
    <HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>

<Reference Include="fsdk_dotnet">
    <HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>
XML

Also delete any HTML2PDF engine folders that were unpacked separately.

Step 2: Update Namespaces

// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;

// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;

// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Rendering
Imports IronPdf.Editing
$vbLabelText   $csharpLabel

Step 3: Initialize IronPDF

One of the most significant improvements in this Foxit PDF migration is eliminating the complex initialization and cleanup pattern:

// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
    throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release();  // Don't forget this!

// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// That's it! No Release() needed
// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
    throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release();  // Don't forget this!

// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// That's it! No Release() needed
Imports System

' Before (Foxit PDF)
Dim sn As String = "YOUR_SERIAL_NUMBER"
Dim key As String = "YOUR_LICENSE_KEY"
Dim error_code As ErrorCode = Library.Initialize(sn, key)
If error_code <> ErrorCode.e_ErrSuccess Then
    Throw New Exception("Failed to initialize Foxit PDF SDK")
End If
' ... your code ...
Library.Release()  ' Don't forget this!

' After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
' That's it! No Release() needed
$vbLabelText   $csharpLabel

Step 4: Basic Conversion Pattern

// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
Convert.FromHTML(htmlContent, @"C:\Foxit\html2pdf_engine", "",
                 settings, "output.pdf", 30);
Library.Release();

// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
Convert.FromHTML(htmlContent, @"C:\Foxit\html2pdf_engine", "",
                 settings, "output.pdf", 30);
Library.Release();

// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
' Before (Foxit PDF)
Library.Initialize(sn, key)
Dim settings As New HTML2PDFSettingData()
settings.page_width = 612.0F
settings.page_height = 792.0F
Convert.FromHTML(htmlContent, "C:\Foxit\html2pdf_engine", "", settings, "output.pdf", 30)
Library.Release()

' After (IronPDF)
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
$vbLabelText   $csharpLabel

Complete API Reference

Namespace Mapping

Foxit PDF Namespace IronPDF Equivalent
foxit IronPdf
foxit.common IronPdf
foxit.common.fxcrt N/A
foxit.pdf IronPdf
foxit.pdf.annots IronPdf.Editing
foxit.addon.conversion IronPdf.Rendering

Core Class Mapping

Foxit PDF SDK Class IronPDF Equivalent
Library N/A
PDFDoc PdfDocument
PDFPage PdfDocument.Pages[i]
HTML2PDF ChromePdfRenderer
TextPage pdf.ExtractTextFromPage(i)
Watermark TextStamper / ImageStamper
Security SecuritySettings
Form pdf.Form
Metadata pdf.MetaData

PDFDoc Methods

Foxit PDFDoc IronPDF PdfDocument
new PDFDoc(path) PdfDocument.FromFile(path)
doc.LoadW(password) PdfDocument.FromFile(path, password)
doc.GetPageCount() pdf.PageCount
doc.GetPage(index) pdf.Pages[index]
doc.SaveAs(path, flags) pdf.SaveAs(path)
doc.Close() pdf.Dispose() or using statement
doc.InsertDocument() PdfDocument.Merge()

HTML2PDF / Conversion

Foxit HTML2PDF IronPDF Equivalent
new HTML2PDFSettingData() new ChromePdfRenderer()
settings.page_width RenderingOptions.PaperSize
settings.page_height RenderingOptions.SetCustomPaperSize()
Convert.FromHTML(html, engine, ...) renderer.RenderHtmlAsPdf(html)
Convert.FromHTML(url, engine, ...) renderer.RenderUrlAsPdf(url)

Watermark Settings

Foxit Watermark IronPDF Equivalent
new Watermark(doc, text, font, size, color) new TextStamper()
WatermarkSettings.position VerticalAlignment + HorizontalAlignment
WatermarkSettings.rotation Rotation
WatermarkSettings.opacity Opacity
watermark.InsertToAllPages() pdf.ApplyStamp(stamper)

Code Examples

Example 1: HTML to PDF Conversion

Before (Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
// HTML-to-PDF requires the separate Foxit HTML2PDF engine (engine_path),
// obtained from Foxit support/sales — not in the NuGet package.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        HTML2PDFSettingData settingData = new HTML2PDFSettingData();
        settingData.page_width = 612.0f;
        settingData.page_height = 792.0f;
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;

        Convert.FromHTML(
            "<html><body><h1>Hello World</h1></body></html>",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}
// NuGet: Install-Package Foxit.SDK.Dotnet
// HTML-to-PDF requires the separate Foxit HTML2PDF engine (engine_path),
// obtained from Foxit support/sales — not in the NuGet package.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        HTML2PDFSettingData settingData = new HTML2PDFSettingData();
        settingData.page_width = 612.0f;
        settingData.page_height = 792.0f;
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;

        Convert.FromHTML(
            "<html><body><h1>Hello World</h1></body></html>",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}
Imports foxit
Imports foxit.common
Imports foxit.addon.conversion
Imports System

Class Program
    Shared Sub Main()
        Library.Initialize("sn", "key")

        Dim settingData As New HTML2PDFSettingData()
        settingData.page_width = 612.0F
        settingData.page_height = 792.0F
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage

        Convert.FromHTML(
            "<html><body><h1>Hello World</h1></body></html>",
            "C:\Foxit\html2pdf_engine",   ' engine_path (separate download)
            "",                           ' cookies path
            settingData,
            "output.pdf",
            30)                           ' timeout (seconds)

        Library.Release()
    End Sub
End Class
$vbLabelText   $csharpLabel

After (IronPDF):

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

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
        pdf.SaveAs("output.pdf");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>")
        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

The IronPDF approach reduces 15+ lines of configuration code to just 4 lines. No library initialization, no explicit cleanup, no complex settings objects. For more HTML rendering options, see the HTML to PDF documentation.

Example 2: URL to PDF Conversion

Before (Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
// Convert.FromHTML accepts either a URL or a literal HTML string in the
// first argument; the URL form is what does URL-to-PDF.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        HTML2PDFSettingData settingData = new HTML2PDFSettingData();
        settingData.page_width = 612.0f;
        settingData.page_height = 792.0f;
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;

        Convert.FromHTML(
            "https://www.example.com",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}
// NuGet: Install-Package Foxit.SDK.Dotnet
// Convert.FromHTML accepts either a URL or a literal HTML string in the
// first argument; the URL form is what does URL-to-PDF.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        HTML2PDFSettingData settingData = new HTML2PDFSettingData();
        settingData.page_width = 612.0f;
        settingData.page_height = 792.0f;
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;

        Convert.FromHTML(
            "https://www.example.com",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}
Imports foxit
Imports foxit.common
Imports foxit.addon.conversion
Imports System

Module Program
    Sub Main()
        Library.Initialize("sn", "key")

        Dim settingData As New HTML2PDFSettingData()
        settingData.page_width = 612.0F
        settingData.page_height = 792.0F
        settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage

        Convert.FromHTML(
            "https://www.example.com",
            "C:\Foxit\html2pdf_engine",   ' engine_path (separate download)
            "",                           ' cookies path
            settingData,
            "output.pdf",
            30)                          ' timeout (seconds)

        Library.Release()
    End Sub
End Module
$vbLabelText   $csharpLabel

After (IronPDF):

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

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
        pdf.SaveAs("output.pdf");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF's built-in Chromium engine handles JavaScript execution, CSS rendering, and dynamic content automatically. Learn more about URL to PDF conversion.

Example 3: Adding Watermarks

Before (Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
using foxit;
using foxit.common;
using foxit.pdf;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        using (PDFDoc doc = new PDFDoc("input.pdf"))
        {
            doc.Load("");

            WatermarkSettings settings = new WatermarkSettings();
            settings.flags = (int)Watermark.Flags.e_FlagASPageContents;
            settings.position = Position.e_PosCenter;
            settings.rotation = -45.0f;
            settings.opacity = 50;     // 0-100 in newer SDKs

            WatermarkTextProperties props = new WatermarkTextProperties();
            props.font = new Font(Font.StandardID.e_StdIDHelvetica);
            props.font_size = 48.0f;
            props.color = 0xFF0000;
            props.alignment = Alignment.e_AlignmentCenter;

            Watermark watermark = new Watermark(doc, "Confidential", props, settings);

            // No InsertToAllPages helper — iterate pages explicitly.
            for (int i = 0; i < doc.GetPageCount(); i++)
            {
                using (PDFPage page = doc.GetPage(i))
                {
                    watermark.InsertToPage(page);
                }
            }

            doc.SaveAs("output.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
        }

        Library.Release();
    }
}
// NuGet: Install-Package Foxit.SDK.Dotnet
using foxit;
using foxit.common;
using foxit.pdf;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        using (PDFDoc doc = new PDFDoc("input.pdf"))
        {
            doc.Load("");

            WatermarkSettings settings = new WatermarkSettings();
            settings.flags = (int)Watermark.Flags.e_FlagASPageContents;
            settings.position = Position.e_PosCenter;
            settings.rotation = -45.0f;
            settings.opacity = 50;     // 0-100 in newer SDKs

            WatermarkTextProperties props = new WatermarkTextProperties();
            props.font = new Font(Font.StandardID.e_StdIDHelvetica);
            props.font_size = 48.0f;
            props.color = 0xFF0000;
            props.alignment = Alignment.e_AlignmentCenter;

            Watermark watermark = new Watermark(doc, "Confidential", props, settings);

            // No InsertToAllPages helper — iterate pages explicitly.
            for (int i = 0; i < doc.GetPageCount(); i++)
            {
                using (PDFPage page = doc.GetPage(i))
                {
                    watermark.InsertToPage(page);
                }
            }

            doc.SaveAs("output.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
        }

        Library.Release();
    }
}
Imports foxit
Imports foxit.common
Imports foxit.pdf
Imports System

Module Program
    Sub Main()
        Library.Initialize("sn", "key")

        Using doc As New PDFDoc("input.pdf")
            doc.Load("")

            Dim settings As New WatermarkSettings()
            settings.flags = CInt(Watermark.Flags.e_FlagASPageContents)
            settings.position = Position.e_PosCenter
            settings.rotation = -45.0F
            settings.opacity = 50 ' 0-100 in newer SDKs

            Dim props As New WatermarkTextProperties()
            props.font = New Font(Font.StandardID.e_StdIDHelvetica)
            props.font_size = 48.0F
            props.color = &HFF0000
            props.alignment = Alignment.e_AlignmentCenter

            Dim watermark As New Watermark(doc, "Confidential", props, settings)

            ' No InsertToAllPages helper — iterate pages explicitly.
            For i As Integer = 0 To doc.GetPageCount() - 1
                Using page As PDFPage = doc.GetPage(i)
                    watermark.InsertToPage(page)
                End Using
            Next

            doc.SaveAs("output.pdf", CInt(PDFDoc.SaveFlags.e_SaveFlagNoOriginal))
        End Using

        Library.Release()
    End Sub
End Module
$vbLabelText   $csharpLabel

After (IronPDF):

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

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        pdf.ApplyWatermark(new TextStamper()
        {
            Text = "Confidential",
            FontSize = 48,
            Opacity = 50,
            Rotation = -45,
            VerticalAlignment = VerticalAlignment.Middle,
            HorizontalAlignment = HorizontalAlignment.Center
        });
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        pdf.ApplyWatermark(new TextStamper()
        {
            Text = "Confidential",
            FontSize = 48,
            Opacity = 50,
            Rotation = -45,
            VerticalAlignment = VerticalAlignment.Middle,
            HorizontalAlignment = HorizontalAlignment.Center
        });
        pdf.SaveAs("output.pdf");
    }
}
Imports IronPdf
Imports IronPdf.Editing
Imports System

Class Program
    Shared Sub Main()
        Dim pdf = PdfDocument.FromFile("input.pdf")
        pdf.ApplyWatermark(New TextStamper() With {
            .Text = "Confidential",
            .FontSize = 48,
            .Opacity = 50,
            .Rotation = -45,
            .VerticalAlignment = VerticalAlignment.Middle,
            .HorizontalAlignment = HorizontalAlignment.Center
        })
        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF's TextStamper provides intuitive property-based configuration instead of separate settings objects and manual page iteration. See the complete watermarking documentation for additional options.

Example 4: URL to PDF with Headers and Footers

Before (Foxit PDF SDK):

using foxit;
using foxit.addon.conversion;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        try
        {
            HTML2PDFSettingData settings = new HTML2PDFSettingData();
            settings.page_width = 595.0f;  // A4
            settings.page_height = 842.0f;
            settings.page_margin_top = 100.0f;
            settings.page_margin_bottom = 100.0f;

            // Foxit PDF SDK has limited header/footer support
            // Often requires post-processing or additional code

            Convert.FromHTML(
                "https://www.example.com",
                @"C:\Foxit\html2pdf_engine",  // engine_path (separate download)
                "",                            // cookies path
                settings,
                "webpage.pdf",
                30);                           // timeout (seconds)
        }
        finally
        {
            Library.Release();
        }
    }
}
using foxit;
using foxit.addon.conversion;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        try
        {
            HTML2PDFSettingData settings = new HTML2PDFSettingData();
            settings.page_width = 595.0f;  // A4
            settings.page_height = 842.0f;
            settings.page_margin_top = 100.0f;
            settings.page_margin_bottom = 100.0f;

            // Foxit PDF SDK has limited header/footer support
            // Often requires post-processing or additional code

            Convert.FromHTML(
                "https://www.example.com",
                @"C:\Foxit\html2pdf_engine",  // engine_path (separate download)
                "",                            // cookies path
                settings,
                "webpage.pdf",
                30);                           // timeout (seconds)
        }
        finally
        {
            Library.Release();
        }
    }
}
Imports foxit
Imports foxit.addon.conversion

Class Program
    Shared Sub Main()
        Library.Initialize("sn", "key")

        Try
            Dim settings As New HTML2PDFSettingData()
            settings.page_width = 595.0F ' A4
            settings.page_height = 842.0F
            settings.page_margin_top = 100.0F
            settings.page_margin_bottom = 100.0F

            ' Foxit PDF SDK has limited header/footer support
            ' Often requires post-processing or additional code

            Convert.FromHTML(
                "https://www.example.com",
                "C:\Foxit\html2pdf_engine",  ' engine_path (separate download)
                "",                          ' cookies path
                settings,
                "webpage.pdf",
                30)                          ' timeout (seconds)
        Finally
            Library.Release()
        End Try
    End Sub
End Class
$vbLabelText   $csharpLabel

After (IronPDF):

using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
        renderer.RenderingOptions.PrintHtmlBackgrounds = true;
        renderer.RenderingOptions.WaitFor.RenderDelay(3000);  // Wait for JS

        // Built-in header/footer support
        renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
        {
            HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
            DrawDividerLine = true
        };

        renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
        {
            HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
            DrawDividerLine = true
        };

        var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
        pdf.SaveAs("webpage.pdf");
    }
}
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
        renderer.RenderingOptions.PrintHtmlBackgrounds = true;
        renderer.RenderingOptions.WaitFor.RenderDelay(3000);  // Wait for JS

        // Built-in header/footer support
        renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
        {
            HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
            DrawDividerLine = true
        };

        renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
        {
            HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
            DrawDividerLine = true
        };

        var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
        pdf.SaveAs("webpage.pdf");
    }
}
Imports IronPdf

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
        renderer.RenderingOptions.PrintHtmlBackgrounds = True
        renderer.RenderingOptions.WaitFor.RenderDelay(3000) ' Wait for JS

        ' Built-in header/footer support
        renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
            .HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
            .DrawDividerLine = True
        }

        renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {
            .HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
            .DrawDividerLine = True
        }

        Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
        pdf.SaveAs("webpage.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF provides native headers and footers support with HTML styling and dynamic page number placeholders.

Example 5: PDF Security and Encryption

Before (Foxit PDF SDK):

using foxit;
using foxit.pdf;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        try
        {
            using (PDFDoc doc = new PDFDoc("input.pdf"))
            {
                doc.LoadW("");

                // Build the encryption data (cipher, key length, permissions)
                using (StdEncryptData encryptData = new StdEncryptData(
                    true,                                    // is_encrypt_metadata
                    (int)(PDFDoc.UserPermissions.e_PermPrint |
                          PDFDoc.UserPermissions.e_PermModify),
                    SecurityHandler.CipherType.e_CipherAES,
                    16))                                     // key length (bytes) -> AES-128
                using (StdSecurityHandler securityHandler = new StdSecurityHandler())
                {
                    securityHandler.Initialize(encryptData, "user_password", "owner_password");
                    doc.SetSecurityHandler(securityHandler);
                }

                doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
            }
        }
        finally
        {
            Library.Release();
        }
    }
}
using foxit;
using foxit.pdf;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        try
        {
            using (PDFDoc doc = new PDFDoc("input.pdf"))
            {
                doc.LoadW("");

                // Build the encryption data (cipher, key length, permissions)
                using (StdEncryptData encryptData = new StdEncryptData(
                    true,                                    // is_encrypt_metadata
                    (int)(PDFDoc.UserPermissions.e_PermPrint |
                          PDFDoc.UserPermissions.e_PermModify),
                    SecurityHandler.CipherType.e_CipherAES,
                    16))                                     // key length (bytes) -> AES-128
                using (StdSecurityHandler securityHandler = new StdSecurityHandler())
                {
                    securityHandler.Initialize(encryptData, "user_password", "owner_password");
                    doc.SetSecurityHandler(securityHandler);
                }

                doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
            }
        }
        finally
        {
            Library.Release();
        }
    }
}
Imports foxit
Imports foxit.pdf

Class Program
    Shared Sub Main()
        Library.Initialize("sn", "key")

        Try
            Using doc As New PDFDoc("input.pdf")
                doc.LoadW("")

                ' Build the encryption data (cipher, key length, permissions)
                Using encryptData As New StdEncryptData(True, CType(PDFDoc.UserPermissions.e_PermPrint Or PDFDoc.UserPermissions.e_PermModify, Integer), SecurityHandler.CipherType.e_CipherAES, 16) ' key length (bytes) -> AES-128
                    Using securityHandler As New StdSecurityHandler()
                        securityHandler.Initialize(encryptData, "user_password", "owner_password")
                        doc.SetSecurityHandler(securityHandler)
                    End Using
                End Using

                doc.SaveAs("encrypted.pdf", CType(PDFDoc.SaveFlags.e_SaveFlagNoOriginal, Integer))
            End Using
        Finally
            Library.Release()
        End Try
    End Sub
End Class
$vbLabelText   $csharpLabel

After (IronPDF):

using IronPdf;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");

        // Set passwords
        pdf.SecuritySettings.OwnerPassword = "owner_password";
        pdf.SecuritySettings.UserPassword = "user_password";

        // Set permissions
        pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
        pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
        pdf.SecuritySettings.AllowUserCopyPasteContent = true;
        pdf.SecuritySettings.AllowUserAnnotations = true;

        pdf.SaveAs("encrypted.pdf");
    }
}
using IronPdf;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");

        // Set passwords
        pdf.SecuritySettings.OwnerPassword = "owner_password";
        pdf.SecuritySettings.UserPassword = "user_password";

        // Set permissions
        pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
        pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
        pdf.SecuritySettings.AllowUserCopyPasteContent = true;
        pdf.SecuritySettings.AllowUserAnnotations = true;

        pdf.SaveAs("encrypted.pdf");
    }
}
Imports IronPdf

Class Program
    Shared Sub Main()
        Dim pdf = PdfDocument.FromFile("input.pdf")

        ' Set passwords
        pdf.SecuritySettings.OwnerPassword = "owner_password"
        pdf.SecuritySettings.UserPassword = "user_password"

        ' Set permissions
        pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
        pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll
        pdf.SecuritySettings.AllowUserCopyPasteContent = True
        pdf.SecuritySettings.AllowUserAnnotations = True

        pdf.SaveAs("encrypted.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

Performance Considerations

Reuse ChromePdfRenderer

For optimal performance during your Foxit PDF migration, reuse the ChromePdfRenderer instance—it's thread-safe:

// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
    private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();

    public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}

// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
    var renderer = new ChromePdfRenderer();  // Wasteful
    return renderer.RenderHtmlAsPdf(html).BinaryData;
}
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
    private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();

    public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}

// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
    var renderer = new ChromePdfRenderer();  // Wasteful
    return renderer.RenderHtmlAsPdf(html).BinaryData;
}
Imports System

Public Class PdfService
    Private Shared ReadOnly _renderer As New ChromePdfRenderer()

    Public Function Generate(html As String) As Byte()
        Return _renderer.RenderHtmlAsPdf(html).BinaryData
    End Function

    ' BAD - Creates new instance each time
    Public Function GenerateBad(html As String) As Byte()
        Dim renderer As New ChromePdfRenderer() ' Wasteful
        Return renderer.RenderHtmlAsPdf(html).BinaryData
    End Function
End Class
$vbLabelText   $csharpLabel

Unit Conversion Helper

Foxit PDF SDK uses points; IronPDF uses millimeters. Use this helper during migration:

public static class UnitConverter
{
    public static double PointsToMm(double points) => points * 0.352778;
    public static double MmToPoints(double mm) => mm / 0.352778;
    public static double InchesToMm(double inches) => inches * 25.4;
}

// Usage: Convert Foxit's 72 points (1 inch) to IronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mm
public static class UnitConverter
{
    public static double PointsToMm(double points) => points * 0.352778;
    public static double MmToPoints(double mm) => mm / 0.352778;
    public static double InchesToMm(double inches) => inches * 25.4;
}

// Usage: Convert Foxit's 72 points (1 inch) to IronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mm
Public Module UnitConverter
    Public Function PointsToMm(points As Double) As Double
        Return points * 0.352778
    End Function

    Public Function MmToPoints(mm As Double) As Double
        Return mm / 0.352778
    End Function

    Public Function InchesToMm(inches As Double) As Double
        Return inches * 25.4
    End Function
End Module

' Usage: Convert Foxit's 72 points (1 inch) to IronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72) ' ~25.4mm
$vbLabelText   $csharpLabel

Proper Resource Disposal

// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
    string text = pdf.ExtractAllText();
}  // pdf is disposed automatically
// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
    string text = pdf.ExtractAllText();
}  // pdf is disposed automatically
Imports PdfDocument

' GOOD - Using block for automatic cleanup
Using pdf = PdfDocument.FromFile("large.pdf")
    Dim text As String = pdf.ExtractAllText()
End Using ' pdf is disposed automatically
$vbLabelText   $csharpLabel

Troubleshooting

Issue 1: Library.Initialize() Not Found

Problem: Library.Initialize() doesn't exist in IronPDF.

Solution: IronPDF uses a simpler initialization pattern:

// Foxit PDF
Library.Initialize(sn, key);

// IronPDF - just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Foxit PDF
Library.Initialize(sn, key);

// IronPDF - just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

Issue 2: ErrorCode Handling

Problem: Code checks ErrorCode.e_ErrSuccess but IronPDF doesn't have this.

Solution: Use standard .NET exception handling:

// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }

// IronPDF
try
{
    var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
    Console.WriteLine($"Failed to load PDF: {ex.Message}");
}
// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }

// IronPDF
try
{
    var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
    Console.WriteLine($"Failed to load PDF: {ex.Message}");
}
Imports System
Imports System.IO

' Foxit PDF
Dim err As ErrorCode = doc.LoadW("")
If err <> ErrorCode.e_ErrSuccess Then
    ' handle error
End If

' IronPDF
Try
    Dim pdf = PdfDocument.FromFile("input.pdf")
Catch ex As IOException
    Console.WriteLine($"Failed to load PDF: {ex.Message}")
End Try
$vbLabelText   $csharpLabel

Issue 3: PDFDoc.Close() Not Found

Problem: doc.Close() method doesn't exist in IronPDF.

Solution: Use Dispose() or using statements:

// Foxit PDF
doc.Close();

// IronPDF
pdf.Dispose();
// or better: wrap in using statement
// Foxit PDF
doc.Close();

// IronPDF
pdf.Dispose();
// or better: wrap in using statement
$vbLabelText   $csharpLabel

Migration Checklist

Pre-Migration

  • Inventory all Foxit PDF SDK features used
  • Document license key locations
  • Note all Library.Initialize() and Library.Release() calls
  • List custom settings (page sizes, margins, etc.)
  • Identify error handling patterns using ErrorCode
  • Backup project to version control
  • Obtain IronPDF license key

Package Migration

  • Remove Foxit PDF SDK DLL references from .csproj
  • Remove any private NuGet feed configurations
  • Install IronPDF NuGet package: dotnet add package IronPdf
  • Update namespace imports
  • Set IronPDF license key at startup

Code Migration

  • Remove Library.Initialize() and Library.Release() calls
  • Replace ErrorCode checks with try/catch
  • Replace PDFDoc with PdfDocument
  • Replace Convert.FromHTML(...) with ChromePdfRenderer
  • Update page access from GetPage(i) to Pages[i]
  • Replace SaveAs(path, flags) with SaveAs(path)
  • Replace Close() with Dispose() or using statements
  • Update watermark code to use TextStamper
  • Convert units from points to millimeters

Testing

  • Verify HTML to PDF output matches expectations
  • Test PDF loading and text extraction
  • Verify merge functionality
  • Check watermark appearance
  • Test security/encryption features
  • Validate form field operations
  • Performance testing

Post-Migration

  • Delete Foxit PDF SDK DLLs
  • Remove Foxit-related configuration files
  • Update documentation
  • Clean up unused helper code

Please noteFoxit PDF SDK and Foxit are registered trademarks of Foxit Software Incorporated. This site is not affiliated with, endorsed by, or sponsored by Foxit Software. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.

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

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me