跳至頁尾內容
影片

如何使用 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 loading
  • COM object that has been separated from its underlying RCW cannot be used
  • Timeout expired waiting for print job to complete
  • The printer operation failed because the service is not running
  • Error: 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
依賴Office 必需的 None
分佈 MSI安裝程式 + 手動DLL引用(無NuGet套件) NuGet套件(IronPdf
安裝 MSI + 虛擬列印機驅動程式 + COM註冊 NuGet套件
伺服器支持 通常需要互動式Windows工作階段 無頭運行
HTML渲染 基本(基於Office) 完整的Chromium(CSS3、JS)
.NET支持 有限的.NET Core .NET Framework 4.6.2+ and .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+ or .NET Core 3.1 / .NET 5-9
  • Visual Studio 2019+或VS Code與C#擴展
  • NuGet包管理器存取 -IronPDF許可證金鑰(免費試用可在 ironpdf.com 獲得)

審核Easy 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" .
SHELL

預期的中斷變更

Easy PDF SDK模式 需要更改
new Printer() 使用ChromePdfRenderer
PrintOfficeDocToPDF() Office轉換處理方式不同
RenderHTMLToPDF() RenderHtmlAsPdf()
COM互操作性引用 完全刪除
列印機驅動程式配置 不需要
BeginPrintToFile()回調 原生async/await
互動工作階段要求 無頭運行
基於1的頁碼編索 基於0的索引
超時以秒為單位 超時以毫秒為單位

逐步遷移過程

步驟1:刪除Easy PDF SDK

Easy PDF SDK是作為MSI安裝程式而不是NuGet套件發布的,專案通常直接引用其程式集(如.NET Framework的BCL.easyPDF.PDFConverter.dll或.NET Core的BCL.easyPDF.PDFConverter.NetCore.dll)。 刪除所有引用:

  1. 從"程式和功能"中解除安裝BCL EasyPDF SDK
  2. 從您的.csproj中刪除DLL <Reference>項目
  3. 移除COM互操作性引用
  4. 如果存在,請清理GAC項目

步驟 2:安裝 IronPDF

# Install IronPDF
dotnet add package IronPdf
# Install IronPDF
dotnet add package IronPdf
SHELL

或者通過包管理器控制台:

Install-Package IronPdf

步驟 3:更新命名空間參考

將Easy PDF SDK命名空間替換為IronPDF:

// 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
$vbLabelText   $csharpLabel

完整 API 遷移參考

核心類映射

Easy PDF SDK類 IronPDF等價
Printer ChromePdfRenderer
PDFDocument PdfDocument
HTMLConverter ChromePdfRenderer
PrinterConfiguration ChromePdfRenderOptions
PageOrientation PdfPaperOrientation
PageSize PdfPaperSize
SecurityHandler PdfDocument.SecuritySettings

PDF建立方法

Easy 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操作方法

Easy 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() using
doc.ExtractText() pdf.ExtractAllText()

配置選項

Easy 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

Easy 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
$vbLabelText   $csharpLabel

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

IronPDF將HTML渲染折疊到一個渲染器調用中,並讓Close()模式。

URL 到 PDF 轉換

Easy 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
$vbLabelText   $csharpLabel

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

合併多個 PDF

Easy 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
$vbLabelText   $csharpLabel

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

IronPDF的靜態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")
$vbLabelText   $csharpLabel

頭部和尾部

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

欲了解更多選項,請參見 頁眉和頁腳文件

異步PDF生成

Easy PDF SDK使用基於回調的非同步模式。 IronPDF支持原生async/await:

Easy 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()
$vbLabelText   $csharpLabel

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

關鍵遷移注意事項

頁索引更改

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)
$vbLabelText   $csharpLabel

以毫秒為單位的超時

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

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

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)
$vbLabelText   $csharpLabel

問題:COM互操作性錯誤

徵狀: 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)
$vbLabelText   $csharpLabel

問題:背景未列印

徵狀: CSS背景缺失

解決方案: 啟用背景列印:

renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PrintHtmlBackgrounds = True
$vbLabelText   $csharpLabel

後遷移檢查清單

完成程式碼遷移後,請驗證以下內容:

  • 使用IronPDF的Chromium引擎驗證PDF輸出質量
  • 測試所有邊緣案例的複雜HTML/CSS
  • 驗證伺服器部署在無互動工作階段下運作
  • 測試Docker/容器部署
  • 從部署中刪除BCL EasyPDF安裝程式
  • 從伺服器上移除Office安裝(已不再需要)
  • 使用新的NuGet套件更新CI/CD管道

其他資源


從Easy PDF SDK遷移到IronPDF可以在PDF生成路徑中去除虛擬列印機驅動程式、COM互操作性和僅限Windows的限制。 基於Chromium的渲染帶來了現代CSS3和JavaScript支持,而且相同的程式碼庫可以在Docker、Kubernetes和基於Linux的雲端環境中運行,這對於easyPDF SDK支持的部署模型難以針對的目標。

請注意BCL easyPDF SDK,Easy PDF SDK和Apryse是其各自所有者註冊的商標。 本網站與BCL Technologies或Apryse無關,也未經其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,反映撰寫時公開可用的資訊。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話