如何在C#中管理登录和身份验证
BCL Technologies,easyPDF SDK 的原始发布商,于 2020年3月 被 Apryse(前身为 PDFTron)收购,现在该产品与 Apryse PDF SDK 一起被定位为遗留 SDK。 SDK 本身依赖于多个遗留技术,这在现代开发环境中造成了部署和维护的挑战。
常见的Easy PDF SDK部署问题
开发人员在使用Easy PDF SDK时经常会遇到这些问题:
bcl.easypdf.interop.easypdfprinter.dll error loadingCOM object that has been separated from its underlying RCW cannot be usedTimeout expired waiting for print job to completeThe printer operation failed because the service is not runningError: Access denied(需要交互会话)Cannot find printer: BCL easyPDF Printer
这些错误通常源于Easy PDF SDK的体系结构,它依赖于虚拟打印机驱动程序、COM 互操作和交互式 Windows 会话,在现代服务器环境中难以重现。
Easy PDF SDK与 IronPDF:主要区别
| 特征 | Easy PDF SDK | IronPDF |
|---|---|---|
| 平台 | 仅限 Windows | Windows、Linux、macOS、Docker |
| 办公依赖性 | 要求 | None |
| 分配 | MSI 安装程序 + 手动 DLL 引用(无 NuGet 包) | NuGet 包 (IronPdf) |
| 安装 | MSI + 虚拟打印机驱动 + COM 注册 | NuGet 软件包 |
| 服务器支持 | 通常需要一个交互式 Windows 会话 | 无头运行 |
| HTML 渲染 | 基础(基于办公室) | 完整的 Chromium(CSS3、JS) |
| .NET支持 | 有限的 .NET Core | .NET Framework 4.6.2+ 和.NET 5/6/7/8/9 |
| 同步模式 | 基于回调 | 本地 async/await |
| 容器支持 | 供应商不支持 | 完整的 Docker/Kubernetes |
平台限制
Easy PDF SDK 针对 Windows 并依赖于 Microsoft Office 安装进行 Office 文档转换,这限制了其在 Linux、macOS 和 Docker 等容器化环境中的使用。 这种依赖性往往使服务器设置更复杂,并将部署绑定到 Windows,对于实践多平台 DevOps 的团队或依赖于 Linux 容器的团队来说是一种限制。
迁移前准备
前提条件
确保您的环境符合这些要求:
- .NET Framework 4.6.2+ 或 .NET Core 3.1 / .NET 5-9
- Visual Studio 2019+ 或带有 C# 扩展的 VS Code
- 访问 NuGet 包管理器 -IronPDF许可证密钥(可在ironpdf.com免费试用)
AuditEasy PDF SDK的使用
在您的解决方案目录中运行这些命令,以识别所有Easy PDF SDK引用:
# Find all BCL using statements
grep -r "using BCL" --include="*.cs" .
# Find Printer/PDFDocument usage
grep -r "Printer\|PDFDocument\|PDFConverter\|HTMLConverter" --include="*.cs" .
# Find COM interop references
grep -r "easyPDF\|BCL.easyPDF" --include="*.csproj" .
# Find configuration settings
grep -r "PageOrientation\|TimeOut\|PrintOffice" --include="*.cs" .
# Find all BCL using statements
grep -r "using BCL" --include="*.cs" .
# Find Printer/PDFDocument usage
grep -r "Printer\|PDFDocument\|PDFConverter\|HTMLConverter" --include="*.cs" .
# Find COM interop references
grep -r "easyPDF\|BCL.easyPDF" --include="*.csproj" .
# Find configuration settings
grep -r "PageOrientation\|TimeOut\|PrintOffice" --include="*.cs" .
值得期待的重大变化
| 简易 PDF SDK 模式 | 更改要求 |
|---|---|
new Printer() |
使用 ChromePdfRenderer |
PrintOfficeDocToPDF() |
以不同方式处理办公室转换 |
RenderHTMLToPDF() |
RenderHtmlAsPdf() |
| COM 互操作参考 | 完全删除 |
| 打印机驱动程序配置 | 不需要 |
BeginPrintToFile() 回调 |
本地 async/await |
| 互动环节要求 | 无头运行 |
| 1 基于页面索引 | 基于 0 的索引 |
| 超时(秒 | 超时(毫秒 |
逐步迁移过程
第 1 步:删除 Easy PDF SDK.
Easy PDF SDK 作为 MSI 安装程序分发,而不是 NuGet 包,项目通常直接引用其程序集(例如 BCL.easyPDF.PDFConverter.dll 用于 .NET Framework 或 BCL.easyPDF.PDFConverter.NetCore.dll 用于 .NET Core)。 删除所有引用:
1.从 "程序和功能 "中卸载 BCL EasyPDF SDK
- 从您的
.csproj中移除 DLL<Reference>条目 3.删除 COM 交互引用 4.清理 GAC 条目(如果存在
步骤2:安装IronPDF
# Install IronPDF
dotnet add package IronPdf
# Install IronPDF
dotnet add package IronPdf
或通过软件包管理器控制台:
Install-Package IronPdf
步骤 3:更新命名空间引用
用IronPDF替换Easy PDF SDK命名空间:
// Remove these
using BCL.easyPDF;
using BCL.easyPDF.PDFConverter;
using BCL.easyPDF.PDFProcessor;
using BCL.easyPDF.Printer;
// Add these
using IronPdf;
using IronPdf.Rendering;
// Remove these
using BCL.easyPDF;
using BCL.easyPDF.PDFConverter;
using BCL.easyPDF.PDFProcessor;
using BCL.easyPDF.Printer;
// Add these
using IronPdf;
using IronPdf.Rendering;
Imports IronPdf
Imports IronPdf.Rendering
完整的 API 迁移参考
核心类映射
| 简易 PDF SDK 类 | IronPDF 同等产品 |
|---|---|
Printer |
ChromePdfRenderer |
PDFDocument |
PdfDocument |
HTMLConverter |
ChromePdfRenderer |
PrinterConfiguration |
ChromePdfRenderOptions |
PageOrientation |
PdfPaperOrientation |
PageSize |
PdfPaperSize |
SecurityHandler |
PdfDocument.SecuritySettings |
PDF 创建方法
| 简易 PDF SDK 方法 | IronPDF 方法 |
|---|---|
printer.RenderHTMLToPDF(html, path) |
renderer.RenderHtmlAsPdf(html).SaveAs(path) |
printer.RenderUrlToPDF(url, path) |
renderer.RenderUrlAsPdf(url).SaveAs(path) |
htmlConverter.ConvertHTML(html, doc) |
renderer.RenderHtmlAsPdf(html) |
htmlConverter.ConvertURL(url, doc) |
renderer.RenderUrlAsPdf(url) |
PDF 操作方法
| 简易 PDF SDK 方法 | IronPDF 方法 |
|---|---|
doc.Append(doc2) |
PdfDocument.Merge(pdf1, pdf2) |
doc.ExtractPages(start, end) |
pdf.CopyPages(start, end) |
doc.DeletePage(index) |
pdf.RemovePages(index) |
doc.GetPageCount() |
pdf.PageCount |
doc.Save(path) |
pdf.SaveAs(path) |
doc.Close() |
pdf.Dispose() 或 using |
doc.ExtractText() |
pdf.ExtractAllText() |
配置选项
| 简易 PDF SDK 选项 | IronPDF 选项 |
|---|---|
config.TimeOut |
RenderingOptions.Timeout |
config.PageOrientation = Landscape |
RenderingOptions.PaperOrientation = Landscape |
config.PageSize = A4 |
RenderingOptions.PaperSize = PdfPaperSize.A4 |
config.MarginTop/Bottom/Left/Right |
RenderingOptions.MarginTop,等。 |
代码迁移示例
HTML字符串到PDF
轻松实现 PDF SDK:
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf = new PDFDocument();
var htmlConverter = new HTMLConverter();
htmlConverter.ConvertHTML("<h1>Hello World</h1>", pdf);
pdf.Save("output.pdf");
pdf.Close();
}
}
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf = new PDFDocument();
var htmlConverter = new HTMLConverter();
htmlConverter.ConvertHTML("<h1>Hello World</h1>", pdf);
pdf.Save("output.pdf");
pdf.Close();
}
}
Imports BCL.easyPDF
Imports System
Class Program
Shared Sub Main()
Dim pdf As New PDFDocument()
Dim htmlConverter As New HTMLConverter()
htmlConverter.ConvertHTML("<h1>Hello World</h1>", pdf)
pdf.Save("output.pdf")
pdf.Close()
End Sub
End Class
IronPDF 实现:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
pdf.SaveAs("output.pdf")
End Sub
End Class
IronPDF 将 HTML 渲染折叠为单个渲染器调用,并让 Dispose 处理清理,省去了单独的 HTMLConverter 步骤和手动 Close() 模式。
URL到PDF转换
轻松实现 PDF SDK:
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf = new PDFDocument();
var htmlConverter = new HTMLConverter();
htmlConverter.ConvertURL("https://example.com", pdf);
pdf.Save("webpage.pdf");
pdf.Close();
}
}
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf = new PDFDocument();
var htmlConverter = new HTMLConverter();
htmlConverter.ConvertURL("https://example.com", pdf);
pdf.Save("webpage.pdf");
pdf.Close();
}
}
Imports BCL.easyPDF
Imports System
Class Program
Shared Sub Main()
Dim pdf As New PDFDocument()
Dim htmlConverter As New HTMLConverter()
htmlConverter.ConvertURL("https://example.com", pdf)
pdf.Save("webpage.pdf")
pdf.Close()
End Sub
End Class
IronPDF 实现:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
}
}
Imports IronPdf
Imports System
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End Module
合并多个 PDF 文件
轻松实现 PDF SDK:
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf1 = new PDFDocument("document1.pdf");
var pdf2 = new PDFDocument("document2.pdf");
pdf1.Append(pdf2);
pdf1.Save("merged.pdf");
pdf1.Close();
pdf2.Close();
}
}
// Reference BCL.easyPDF.PDFConverter.dll (or the .NetCore variant)
// installed by the easyPDF SDK MSI — there is no NuGet package.
using BCL.easyPDF;
using System;
class Program
{
static void Main()
{
var pdf1 = new PDFDocument("document1.pdf");
var pdf2 = new PDFDocument("document2.pdf");
pdf1.Append(pdf2);
pdf1.Save("merged.pdf");
pdf1.Close();
pdf2.Close();
}
}
Imports BCL.easyPDF
Imports System
Module Program
Sub Main()
Dim pdf1 As New PDFDocument("document1.pdf")
Dim pdf2 As New PDFDocument("document2.pdf")
pdf1.Append(pdf2)
pdf1.Save("merged.pdf")
pdf1.Close()
pdf2.Close()
End Sub
End Module
IronPDF 实现:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var pdfs = new List<PdfDocument>
{
PdfDocument.FromFile("document1.pdf"),
PdfDocument.FromFile("document2.pdf")
};
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("merged.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var pdfs = new List<PdfDocument>
{
PdfDocument.FromFile("document1.pdf"),
PdfDocument.FromFile("document2.pdf")
};
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("merged.pdf");
}
}
Imports IronPdf
Imports System
Imports System.Collections.Generic
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim pdfs As New List(Of PdfDocument) From {
PdfDocument.FromFile("document1.pdf"),
PdfDocument.FromFile("document2.pdf")
}
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("merged.pdf")
End Sub
End Module
IronPDF 的静态 Merge 方法直接接受文档集合,取代成对的 Append 模式。
密码保护
IronPDF 实现:
using IronPdf;
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential</h1>");
// Set security
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.OwnerPassword = "owner456";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;
pdf.SaveAs("protected.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential</h1>");
// Set security
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.OwnerPassword = "owner456";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;
pdf.SaveAs("protected.pdf");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Confidential</h1>")
' Set security
pdf.SecuritySettings.UserPassword = "user123"
pdf.SecuritySettings.OwnerPassword = "owner456"
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit
pdf.SaveAs("protected.pdf")
页眉和页脚
Easy PDF SDK 在其 HTML 转换路径中没有提供专用的页眉/页脚 API; 页眉和页脚通常直接嵌入在源 HTML 中。IronPDF提供专用的页眉/页脚对象:
using IronPdf;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='text-align:center; font-size:12px; font-family:Arial;'>
Company Name - Confidential
</div>",
DrawDividerLine = true,
MaxHeight = 30
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='text-align:center; font-size:10px;'>
Page {page} of {total-pages}
</div>",
DrawDividerLine = true,
MaxHeight = 25
};
var pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>");
pdf.SaveAs("with_headers.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='text-align:center; font-size:12px; font-family:Arial;'>
Company Name - Confidential
</div>",
DrawDividerLine = true,
MaxHeight = 30
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='text-align:center; font-size:10px;'>
Page {page} of {total-pages}
</div>",
DrawDividerLine = true,
MaxHeight = 25
};
var pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>");
pdf.SaveAs("with_headers.pdf");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='text-align:center; font-size:12px; font-family:Arial;'>
Company Name - Confidential
</div>",
.DrawDividerLine = True,
.MaxHeight = 30
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='text-align:center; font-size:10px;'>
Page {page} of {total-pages}
</div>",
.DrawDividerLine = True,
.MaxHeight = 25
}
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>")
pdf.SaveAs("with_headers.pdf")
有关更多选项,请参阅页眉和页脚文档。
异步 PDF 生成
Easy PDF SDK 使用基于回调的异步模式。IronPDF支持本地 async/await:
轻松实现 PDF SDK:
using BCL.easyPDF;
Printer printer = new Printer();
// BCL uses callback-based async
printer.BeginPrintToFile(
"https://example.com",
"output.pdf",
OnPrintComplete,
OnPrintError
);
Console.ReadLine();
printer.Dispose();
using BCL.easyPDF;
Printer printer = new Printer();
// BCL uses callback-based async
printer.BeginPrintToFile(
"https://example.com",
"output.pdf",
OnPrintComplete,
OnPrintError
);
Console.ReadLine();
printer.Dispose();
Imports BCL.easyPDF
Dim printer As New Printer()
' BCL uses callback-based async
printer.BeginPrintToFile( _
"https://example.com", _
"output.pdf", _
AddressOf OnPrintComplete, _
AddressOf OnPrintError _
)
Console.ReadLine()
printer.Dispose()
IronPDF 实现:
using IronPdf;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var renderer = new ChromePdfRenderer();
// Native async/await
var pdf = await renderer.RenderUrlAsPdfAsync("https://example.com");
await pdf.SaveAsAsync("output.pdf");
Console.WriteLine("PDF created: output.pdf");
}
}
using IronPdf;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var renderer = new ChromePdfRenderer();
// Native async/await
var pdf = await renderer.RenderUrlAsPdfAsync("https://example.com");
await pdf.SaveAsAsync("output.pdf");
Console.WriteLine("PDF created: output.pdf");
}
}
Imports IronPdf
Imports System.Threading.Tasks
Class Program
Shared Async Function Main() As Task
Dim renderer = New ChromePdfRenderer()
' Native async/await
Dim pdf = Await renderer.RenderUrlAsPdfAsync("https://example.com")
Await pdf.SaveAsAsync("output.pdf")
Console.WriteLine("PDF created: output.pdf")
End Function
End Class
关键迁移说明
页面索引更改
Easy PDF SDK 使用基于 1 的索引。IronPDF使用基于 0 的索引:
// Easy PDF SDK: 1-based
doc.ExtractPages(1, 5);
// IronPDF: 0-based
pdf.CopyPages(0, 4);
// Easy PDF SDK: 1-based
doc.ExtractPages(1, 5);
// IronPDF: 0-based
pdf.CopyPages(0, 4);
' Easy PDF SDK: 1-based
doc.ExtractPages(1, 5)
' IronPDF: 0-based
pdf.CopyPages(0, 4)
超时(毫秒)
Easy PDF SDK 使用秒作为超时值。IronPDF使用毫秒:
// Easy PDF SDK: seconds
config.TimeOut = 120;
// IronPDF: milliseconds
renderer.RenderingOptions.Timeout = 120000;
// Easy PDF SDK: seconds
config.TimeOut = 120;
// IronPDF: milliseconds
renderer.RenderingOptions.Timeout = 120000;
' Easy PDF SDK: seconds
config.TimeOut = 120
' IronPDF: milliseconds
renderer.RenderingOptions.Timeout = 120000
ASP.NET Core 集成
由于交互式会话的要求,Easy PDF SDK 在网络环境中很难发挥作用。
IronPDF模式:
[ApiController]
[Route("[controller]")]
public class PdfController : ControllerBase
{
[HttpGet("generate")]
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>");
return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
[HttpGet("generate-async")]
public async Task<IActionResult> GeneratePdfAsync()
{
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>");
return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
}
[ApiController]
[Route("[controller]")]
public class PdfController : ControllerBase
{
[HttpGet("generate")]
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>");
return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
[HttpGet("generate-async")]
public async Task<IActionResult> GeneratePdfAsync()
{
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>");
return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
}
Imports Microsoft.AspNetCore.Mvc
<ApiController>
<Route("[controller]")>
Public Class PdfController
Inherits ControllerBase
<HttpGet("generate")>
Public Function GeneratePdf() As IActionResult
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>")
Return File(pdf.BinaryData, "application/pdf", "report.pdf")
End Function
<HttpGet("generate-async")>
Public Async Function GeneratePdfAsync() As Task(Of IActionResult)
Dim renderer = New ChromePdfRenderer()
Dim pdf = Await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>")
Return File(pdf.BinaryData, "application/pdf", "report.pdf")
End Function
End Class
Docker 部署
Easy PDF SDK 不是为 Linux 容器设计的 —— 其支持的配置是 Windows 配合 Microsoft Office、虚拟打印机驱动程序,以及(在大多数设置中)交互式桌面会话,这使得典型的基于 Linux 的 Docker 工作流变得不切实际。
IronPDF Docker 配置:
FROM mcr.microsoft.com/dotnet/aspnet:8.0
# Install Chromium dependencies
RUN apt-get update && apt-get install -y \
libc6 libgdiplus libx11-6 libxcomposite1 \
libxdamage1 libxrandr2 libxss1 libxtst6 \
libnss3 libatk-bridge2.0-0 libgtk-3-0 \
libgbm1 libasound2 fonts-liberation \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]
常见迁移问题的故障排除
问题:未找到打印机
症状: Cannot find printer: BCL easyPDF Printer
解决方案:IronPDF 不需要打印机驱动程序:
// Just use the renderer directly
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
// Just use the renderer directly
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)
问题:COM 互操作错误
症状: DLL error loading 或 RCW 错误
解决方案:删除所有 COM 引用,使用IronPDF的托管 API。
问题:服务器超时
症状:PDF 生成在网络服务器上挂起
解决方案:IronPDF可无头运行,无需交互会话:
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.Timeout = 60000; // Reliable timeout
var pdf = renderer.RenderHtmlAsPdf(html);
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.Timeout = 60000; // Reliable timeout
var pdf = renderer.RenderHtmlAsPdf(html);
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.Timeout = 60000 ' Reliable timeout
Dim pdf = renderer.RenderHtmlAsPdf(html)
问题:背景未打印
症状:CSS 背景丢失
解决方案:启用背景打印:
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PrintHtmlBackgrounds = True
迁移后核对表
完成代码迁移后,请验证以下内容:
- 使用IronPDF的 Chromium 引擎验证 PDF 输出质量
- 使用复杂的 HTML/CSS 测试所有极端情况
- 验证服务器部署在没有交互式会话的情况下是否正常工作
- 测试 Docker/容器部署
- 从部署中移除 BCL EasyPDF 安装程序
- 从服务器上移除 Office 安装(不再需要)
- 使用新的 NuGet 包更新 CI/CD 管道
其他资源
从Easy PDF SDK迁移到IronPDF移除了虚拟打印机驱动程序、COM 互操作和仅限 Windows 的限制从 PDF 生成路径中。 基于 Chromium 的渲染带来了现代 CSS3 和 JavaScript 支持,并且相同的代码基于 Docker、Kubernetes 和基于 Linux 的云环境运行,这些环境在Easy PDF SDK支持的部署模型下很难以定位。

