跳至页脚内容
迁移指南

如何用 C# 从 PdfiumViewer 迁移到 IronPDF

从PdfiumViewer迁移到 IronPdf:完整的 C# 迁移指南。

从PdfiumViewer迁移到IronPDF可将您的 .NET PDF 工作流程从具有本地二进制依赖关系的仅用于 Windows 窗体查看的库迁移到全面的 PDF 解决方案,该解决方案可在所有 .NET 应用程序类型中处理创建、操作、文本提取和渲染。本指南提供了一个完整的、循序渐进的迁移路径,消除了平台限制,同时增加了PdfiumViewer无法提供的功能。

为什么从 IronPdf 迁移到 IronPDF?

了解 PdfiumViewer。

PdfiumViewer 是 PDFium 的 .NET 封装程序,PDFium 是 Google Chrome 浏览器中使用的 PDF 渲染引擎。 它提供了一个简单而强大的解决方案,可将 PDF 查看直接集成到 Windows 窗体应用程序中,提供高性能、高保真的 PDF 渲染功能。

但是,请务必记住,PdfiumViewer 只是一个查看器。 它不支持 PDF 的创建、编辑或操作,这可能会限制对查看功能有更高要求的应用程序。 此外,其不确定的维护状态也会给生产应用程序带来风险--其持续开发和维护存在一定的不确定性,这可能会成为长期项目的顾虑。

PdfiumViewer的关键限制

1.仅查看功能:无法通过 HTML、图像或编程创建 PDF。PdfiumViewer的功能仅限于查看 PDF,与IronPDF等库不同,它不支持 PDF 创建、编辑、合并或其他操作功能。

2.Windows 窗体专用:该库专注于 Windows 窗体应用程序,不支持其他用户界面框架。

3.无 PDF 操作:不能合并、分割或修改 PDF 内容。

4.本地二进制依赖性:需要特定平台的 PDFium 二进制文件(x86 和 x64 pdfium.dll 文件)。

5.不确定的维护:更新有限,长期支持不明确。

6.无文本提取:PdfiumViewer 没有内置文本提取功能,您需要使用 OCR 或其他库。 它只能将页面呈现为图像。

7.No HTML to PDF:PdfiumViewer 主要是 PDF 查看器/渲染器,而不是生成器。 不能直接将 HTML 转换为 PDF。 您需要使用另一个库,如 wkhtmltopdf 或类似库。

8.无页眉/页脚:不能添加页码或重复内容。

9.无水印:不能在文档上覆盖印记。

10.无安全功能:无法对 PDF 进行加密或密码保护。

PdfiumViewer与IronPDF对比

方面PdfiumViewerIronPDF
主要关注点WinForms PDF 查看器完整的 PDF 解决方案
许可阿帕奇 2.0商业翻译
PDF 创建✓ (HTML、URL、图片)
PDF 操作✓(合并、拆分、编辑)
HTML 到 PDF✓(Chromium 引擎)
文本提取
水印
页眉/页脚
安全性
内置浏览器✗(侧重于后端)
平台支持仅限 Windows 窗体控制台、网络、桌面
框架支持.NET Framework.NET Framework, Core, 5+
维护不确定活跃

对于计划在 2025 年和 2026 年之前采用 .NET 10 和 C# 14 的团队来说,IronPDF 提供了一个全面的、积极维护的基础,适用于所有 .NET 应用程序类型,消除了 Windows 窗体限制和本地二进制的复杂性。


开始之前

前提条件

1..NET环境:.NET Framework 4.6.2+ 或 .NET Core 3.1+ / .NET 5/6/7/8/9+ 2.NuGet 访问:安装 NuGet 软件包的能力 3.IronPDF 许可证:从 ironpdf.com 获取许可证密钥

NuGet 软件包变更

# RemovePdfiumViewerpackages
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86.v8-xfa
dotnet remove package PdfiumViewer.Native.x64.v8-xfa

# Install IronPDF
dotnet add package IronPdf
# RemovePdfiumViewerpackages
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86.v8-xfa
dotnet remove package PdfiumViewer.Native.x64.v8-xfa

# Install IronPDF
dotnet add package IronPdf
SHELL

许可配置

// 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";
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

确定PdfiumViewer的用法

# FindPdfiumViewerusage
grep -r "PdfiumViewer\|PdfViewer\|PdfDocument\.Load" --include="*.cs" .

# Find native binary references
grep -r "pdfium\.dll\|Native\.x86\|Native\.x64" --include="*.csproj" .

# Find viewer control usage
grep -r "PdfViewer" --include="*.cs" --include="*.Designer.cs" .
# FindPdfiumViewerusage
grep -r "PdfiumViewer\|PdfViewer\|PdfDocument\.Load" --include="*.cs" .

# Find native binary references
grep -r "pdfium\.dll\|Native\.x86\|Native\.x64" --include="*.csproj" .

# Find viewer control usage
grep -r "PdfViewer" --include="*.cs" --include="*.Designer.cs" .
SHELL

完整的 API 参考

命名空间变更

// PdfiumViewer
using PdfiumViewer;

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// PdfiumViewer
using PdfiumViewer;

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

核心类映射

PdfiumViewerIronPDF备注
<代码>PDF 文档</代码<代码>PDF 文档</代码名称相同,功能不同
<代码>PDFViewer</代码(无对等词)IronPdf 以后台为重点
<代码>PDFRenderer</代码<代码>ChromePdfRenderer</代码PDF 创建
(不可用)_<代码>HtmlHeaderFooter</代码页眉/页脚

文档加载映射

PdfiumViewerIronPDF备注
<代码>PdfDocument.Load(path)</代码<代码>PdfDocument.FromFile(路径)</代码从文件加载
<代码>PdfDocument.Load(stream)</代码<代码>PdfDocument.FromStream(流)</代码从流加载
<代码>PdfDocument.Load(bytes)</代码<代码>PdfDocument.FromBinaryData(字节)</代码从字节加载

文档属性映射

PdfiumViewerIronPDF备注
<代码>document.PageCount</代码<代码>document.PageCount</代码相同
<代码>document.PageSizes</代码<代码>document.Pages[i].Width/Height</代码每页访问
<代码>document.GetPageSize(index)</代码<代码>document.Pages[index].Width/Height</代码直接属性

页面渲染映射

PdfiumViewerIronPDF备注
<代码>document.Render(pageIndex, dpiX, dpiY, forPrinting)</ 代码<代码>pdf.ToBitmap(pageIndex)</代码返回位图数组
document.Render(pageIndex, width, height, dpiX, dpiY, flags) </代码<代码>pdf.RasterizeToImageFiles(path, dpi)</ 代码批量渲染

保存文档映射

PdfiumViewerIronPDF备注
<代码>document.Save(路径)</代码<代码>pdf.SaveAs(路径)</代码不同的方法名称
<代码>document.Save(流)</代码<代码>pdf.Stream</代码访问流
(不可用)_<代码>pdf.BinaryData</代码获取字节

PdfiumViewer中不提供的新功能

IronPdf 特点说明
<代码>pdf.ExtractAllText()</代码从所有页面提取文本
<代码>pdf.ExtractTextFromPage(index)</代码从特定页面提取文本
<代码>ChromePdfRenderer.RenderHtmlAsPdf()</代码从 HTML 创建
<代码>ChromePdfRenderer.RenderUrlAsPdf()</代码从 URL 创建
<代码>PdfDocument.Merge()</代码合并 PDF
<代码>pdf.CopyPages()</代码提取页面
<代码>pdf.RemovePages()</代码删除页面
<代码>pdf.ApplyWatermark()</代码添加水印
<代码>pdf.AddHtmlHeaders()</代码添加页眉
<代码>pdf.AddHtmlFooters()</代码添加页脚
<代码>pdf.SecuritySettings</代码密码保护
<代码>pdf.Form</代码表格填写

代码迁移示例

示例 1:从 PDF 中提取文本

之前 (PdfiumViewer):

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

string pdfPath = "document.pdf";

// PDFiumViewer has limited text extraction capabilities
// It's primarily designed for rendering, not text extraction
using (var document = PdfDocument.Load(pdfPath))
{
    int pageCount = document.PageCount;
    Console.WriteLine($"Total pages: {pageCount}");

    // PDFiumViewer does not have built-in text extraction
    // You would need to use OCR or another library
    // It can only render pages as images
    for (int i = 0; i < pageCount; i++)
    {
        var pageImage = document.Render(i, 96, 96, false);
        Console.WriteLine($"Rendered page {i + 1}");
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.Text;

string pdfPath = "document.pdf";

// PDFiumViewer has limited text extraction capabilities
// It's primarily designed for rendering, not text extraction
using (var document = PdfDocument.Load(pdfPath))
{
    int pageCount = document.PageCount;
    Console.WriteLine($"Total pages: {pageCount}");

    // PDFiumViewer does not have built-in text extraction
    // You would need to use OCR or another library
    // It can only render pages as images
    for (int i = 0; i < pageCount; i++)
    {
        var pageImage = document.Render(i, 96, 96, false);
        Console.WriteLine($"Rendered page {i + 1}");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

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

string pdfPath = "document.pdf";

// Open and extract text from PDF
PdfDocument pdf = PdfDocument.FromFile(pdfPath);

// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);

// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst page text: {pageText}");

Console.WriteLine($"\nTotal pages: {pdf.PageCount}");
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

string pdfPath = "document.pdf";

// Open and extract text from PDF
PdfDocument pdf = PdfDocument.FromFile(pdfPath);

// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);

// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst page text: {pageText}");

Console.WriteLine($"\nTotal pages: {pdf.PageCount}");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

这个例子凸显了一个基本的能力差距。PdfiumViewer 明确指出它 "没有内置文本提取功能","您需要使用 OCR 或其他库"--它只能将页面呈现为图像。 如果您需要使用PdfiumViewer从 PDF 中获取文本,您将被迫渲染为图像并运行 OCR。

IronPDF 使用 ExtractAllText() 对整个文档进行本地文本提取,或使用 ExtractTextFromPage(index) 对特定页面进行本地文本提取。 无需 OCR,无需变通方法--直接从 PDF 内容中提取文本。 有关其他选项,请参阅 文本提取文档

示例 2:HTML 到 PDF 的转换

之前 (PdfiumViewer):

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

// PDFiumViewer is primarily a PDF viewer/renderer, not a generator
// It cannot directly convert HTML to PDF
// You would need to use another library to first create the PDF
// Then use PDFiumViewer to display it:

string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";

// This functionality is NOT available in PDFiumViewer
// You would need a different library like wkhtmltopdf or similar
// PDFiumViewer can only open and display existing PDFs:

string existingPdfPath = "output.pdf";
using (var document = PdfDocument.Load(existingPdfPath))
{
    // Can only render/display existing PDF
    var image = document.Render(0, 300, 300, true);
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System.IO;
using System.Drawing.Printing;

// PDFiumViewer is primarily a PDF viewer/renderer, not a generator
// It cannot directly convert HTML to PDF
// You would need to use another library to first create the PDF
// Then use PDFiumViewer to display it:

string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";

// This functionality is NOT available in PDFiumViewer
// You would need a different library like wkhtmltopdf or similar
// PDFiumViewer can only open and display existing PDFs:

string existingPdfPath = "output.pdf";
using (var document = PdfDocument.Load(existingPdfPath))
{
    // Can only render/display existing PDF
    var image = document.Render(0, 300, 300, true);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

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

string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";

// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Save the PDF
pdf.SaveAs("output.pdf");

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

string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";

// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Save the PDF
pdf.SaveAs("output.pdf");

Console.WriteLine("PDF created successfully!");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

本例展示了两个库之间最显著的功能差异。PdfiumViewer明确指出 "PDFiumViewer 中不提供此功能 "和 "您需要不同的库,如 wkhtmltopdf 或类似库"--PdfiumViewer 只能打开和显示现有的 PDF。

IronPDF 通过<代码>ChromePdfRenderer</代码提供原生 HTML 到 PDF 的转换,其内部使用 Chromium 引擎来准确呈现 HTML、CSS 和 JavaScript。 RenderHtmlAsPdf() 方法可将 HTML 字符串直接转换为 PDF 文档。IronPDF还可以使用 RenderUrlAsPdf() 渲染 URL,使用 RenderHtmlFileAsPdf() 渲染 HTML 文件。 请参阅 HTML 转 PDF 文档,了解全面的示例。

示例 3:PDF 到图像的转换

之前 (PdfiumViewer):

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

string pdfPath = "document.pdf";
string outputImage = "page1.png";

// PDFiumViewer excels at rendering PDFs to images
using (var document = PdfDocument.Load(pdfPath))
{
    // Render first page at 300 DPI
    int dpi = 300;
    using (var image = document.Render(0, dpi, dpi, true))
    {
        // Save as PNG
        image.Save(outputImage, ImageFormat.Png);
        Console.WriteLine($"Page rendered to {outputImage}");
    }

    // Render all pages
    for (int i = 0; i < document.PageCount; i++)
    {
        using (var pageImage = document.Render(i, 150, 150, true))
        {
            pageImage.Save($"page_{i + 1}.png", ImageFormat.Png);
        }
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.Drawing;
using System.Drawing.Imaging;

string pdfPath = "document.pdf";
string outputImage = "page1.png";

// PDFiumViewer excels at rendering PDFs to images
using (var document = PdfDocument.Load(pdfPath))
{
    // Render first page at 300 DPI
    int dpi = 300;
    using (var image = document.Render(0, dpi, dpi, true))
    {
        // Save as PNG
        image.Save(outputImage, ImageFormat.Png);
        Console.WriteLine($"Page rendered to {outputImage}");
    }

    // Render all pages
    for (int i = 0; i < document.PageCount; i++)
    {
        using (var pageImage = document.Render(i, 150, 150, true))
        {
            pageImage.Save($"page_{i + 1}.png", ImageFormat.Png);
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

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

string pdfPath = "document.pdf";
string outputImage = "page1.png";

// Open PDF and convert to images
PdfDocument pdf = PdfDocument.FromFile(pdfPath);

// Convert first page to image
var firstPageImage = pdf.ToBitmap(0);
firstPageImage[0].Save(outputImage);
Console.WriteLine($"Page rendered to {outputImage}");

// Convert all pages to images
var allPageImages = pdf.ToBitmap();
for (int i = 0; i < allPageImages.Length; i++)
{
    allPageImages[i].Save($"page_{i + 1}.png");
    Console.WriteLine($"Saved page {i + 1}");
}

Console.WriteLine($"Total pages converted: {pdf.PageCount}");
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Linq;

string pdfPath = "document.pdf";
string outputImage = "page1.png";

// Open PDF and convert to images
PdfDocument pdf = PdfDocument.FromFile(pdfPath);

// Convert first page to image
var firstPageImage = pdf.ToBitmap(0);
firstPageImage[0].Save(outputImage);
Console.WriteLine($"Page rendered to {outputImage}");

// Convert all pages to images
var allPageImages = pdf.ToBitmap();
for (int i = 0; i < allPageImages.Length; i++)
{
    allPageImages[i].Save($"page_{i + 1}.png");
    Console.WriteLine($"Saved page {i + 1}");
}

Console.WriteLine($"Total pages converted: {pdf.PageCount}");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

这正是PdfiumViewer的优势所在--PDF 图像渲染是其主要优势。 这两个库都能有效地完成这项任务,但模式不同。

PdfiumViewer 使用<代码>document.Render(pageIndex, dpiX, dpiY, forPrinting)</ 代码和嵌套 using 语句进行正确处理。 您需要导入 System.DrawingSystem.Drawing.Imaging 以获得 ImageFormat 枚举。

IronPDF 使用<代码>pdf.ToBitmap(pageIndex)</代码返回一个位图数组。 模式较为简单,没有嵌套处置要求。 对于批量操作,ToBitmap() 不带参数将返回所有页面。 您也可以使用 RasterizeToImageFiles() 直接输出文件。 有关其他渲染选项,请参阅 PDF 转图像文档


本地依赖关系移除

从PdfiumViewer迁移到IronPDF的重大好处之一是消除了本地二进制管理。

之前 (PdfiumViewer) - 复杂部署

MyApp/
├─── bin/
│ ├─── MyApp.dll
│ ├── PdfiumViewer.dll
│ ├── x86/
│ │ └── pdfium.dll
│ └── x64/
│ └── pdfium.dll

后 (IronPDF) - 清洁部署

MyApp/
├─── bin/
│ ├─── MyApp.dll
│ └─── IronPdf.dll # 包含的所有内容

移除本地二进制引用

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

# Remove from .csproj native package references
# <PackageReference Include="PdfiumViewer.Native.x86.v8-xfa" />
# <PackageReference Include="PdfiumViewer.Native.x64.v8-xfa" />
# Delete native PDFium binaries
rm -rf x86/ x64/ runtimes/

# Remove from .csproj native package references
# <PackageReference Include="PdfiumViewer.Native.x86.v8-xfa" />
# <PackageReference Include="PdfiumViewer.Native.x64.v8-xfa" />
SHELL

关键迁移说明

无内置查看器控件

IronPDF 侧重于后台,不包含可视化 PDF 查看器控件:

// PdfiumViewer: Built-in viewer control
pdfViewer.Document = document;

// IronPDF: Use external viewer or web-based approach
pdf.SaveAs(tempPath);
Process.Start(new ProcessStartInfo(tempPath) { UseShellExecute = true });
// PdfiumViewer: Built-in viewer control
pdfViewer.Document = document;

// IronPDF: Use external viewer or web-based approach
pdf.SaveAs(tempPath);
Process.Start(new ProcessStartInfo(tempPath) { UseShellExecute = true });
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

对于查看需求,可考虑使用 Process.Start() 在默认 PDF 查看器、带有 PDF 路径的 WebBrowser 控件或 Syncfusion、DevExpress 或 Telerik 等第三方查看器控件中打开。

文档加载方法更改

// PdfiumViewer
PdfDocument.Load(path)

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

// IronPDF
PdfDocument.FromFile(path)
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

保存方法更改

// PdfiumViewer
document.Save(path)

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

// IronPDF
pdf.SaveAs(path)
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

渲染方法更改

// PdfiumViewer: Returns image with nested using
using (var image = document.Render(0, 150, 150, true))
{
    image.Save("page.png", ImageFormat.Png);
}

// IronPDF: Returns bitmap array
var images = pdf.ToBitmap(0);
images[0].Save("page.png");
// PdfiumViewer: Returns image with nested using
using (var image = document.Render(0, 150, 150, true))
{
    image.Save("page.png", ImageFormat.Png);
}

// IronPDF: Returns bitmap array
var images = pdf.ToBitmap(0);
images[0].Save("page.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

页面大小访问更改

// PdfiumViewer
var size = document.PageSizes[index];
Console.WriteLine($"{size.Width} x {size.Height}");

// IronPDF
var page = pdf.Pages[index];
Console.WriteLine($"{page.Width} x {page.Height}");
// PdfiumViewer
var size = document.PageSizes[index];
Console.WriteLine($"{size.Width} x {size.Height}");

// IronPDF
var page = pdf.Pages[index];
Console.WriteLine($"{page.Width} x {page.Height}");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

功能对比摘要

特征PdfiumViewerIronPDF
加载 PDF
渲染为图像
内置浏览器
打印 PDF
提取文本
从 HTML 创建
从 URL 创建
合并 PDF
拆分 PDF
添加水印
页眉/页脚
表格填写
密码保护
支持 WinForms
ASP.NET 支持
支持 .NET Core有限的
主动维护不确定

迁移清单

迁移前

  • [ ] 确定代码库中PdfiumViewer的所有用法
  • [ ] 使用 PdfViewer 控件列出 WinForms
  • [ ] 记录当前的渲染 DPI 设置
  • [ ] 检查本地二进制引用
  • [ ] 确定打印功能用法
  • [ ] 规划查看器控件更换策略
  • [ ] 获取 IronPdf 许可证密钥

软件包变更

  • [ ] 删除 PdfiumViewer NuGet 软件包
  • [ ] 删除 PdfiumViewer.Native.x86.v8-xfa
  • [ ] 删除 PdfiumViewer.Native.x64.v8-xfa
  • [ ] 从 x86/ 和 x64/ 文件夹中删除本地 pdfium.dll 二进制文件
  • [ ] 安装 IronPDF NuGet 软件包:<代码>dotnet 添加软件包 IronPdf

代码更改

  • [ ] 在启动时添加许可证密钥配置
  • [ ] 将 PdfDocument.Load() 替换为 PdfDocument.FromFile()
  • [ ] 将 document.Save() 替换为 pdf.SaveAs()
  • [ ] 将 document.Render() 替换为 pdf.ToBitmap()RasterizeToImageFiles()
  • [ ] 将 document.PageSizes[i] 替换为 pdf.Pages[i].Width/Height
  • [ ] 使用外部查看器或 Process.Start() 替换 PdfViewer 控件
  • [ ] 添加新功能(文本提取、HTML 转 PDF 等)

后迁移

  • [ ] 测试渲染输出质量
  • [ ] 测试打印功能
  • [ ] 在目标平台上进行测试
  • [ ] 添加新功能(HTML 转 PDF、合并、水印、安全性)
  • [ ] 更新文档

结论

从PdfiumViewer迁移到IronPDF可将您的 PDF 工作流程从仅用于查看的 Windows 窗体库转换为全面的 PDF 解决方案,该解决方案具有跨所有 .NET 应用程序类型的创建、操作、文本提取和渲染功能。

本次迁移的主要变化有 1.范围:仅供查看 → 完整的 PDF 解决方案 2.平台:仅限 Windows 窗体 → 所有 .NET 应用程序类型 3.查看器:内置控件 → 侧重后台(使用外部查看器) 4.加载:<代码>PdfDocument.Load()</代码> → <代码>PdfDocument.FromFile()</代码 5.保存:<代码>Save()</代码> → <代码>SaveAs()</代码 6.渲染Render(index, dpi, dpi, flag)ToBitmap(index)RasterizeToImageFiles() 。 7.新功能:文本提取、HTML 转 PDF、合并、水印、安全性、表单等。

探索完整的IronPDF文档教程API参考,加速您的PdfiumViewer迁移。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。