MIGRATION GUIDES How to Migrate from Apryse PDF to IronPDF in C# Curtis Chau 發表日期:2026年1月11日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 Apryse PDF(前身為 PDFTron)是一款高級企業級 PDF SDK,以其全面的文件處理功能而聞名。 然而,其高昂的定價模式(每位開發者每年 1500 美元以上)、複雜的整合要求以及 C++ 的底層特性,給尋求簡單 PDF 功能的開發團隊帶來了障礙。 本綜合指南提供了從 Apryse PDF 到 IronPDF 的逐步遷移路徑——IronPDF 是一個原生的 .NET PDF 庫,具有現代 C# 約定、更簡單的整合和一次性永久許可。 為什麼要放棄 Apryse PDF? 雖然 Apryse PDF 提供了強大的功能,但多種因素促使開發團隊尋求其他方法來滿足其 PDF 生成需求。 高級定價和訂閱模式 Apryse PDF 的目標客戶是企業級客戶,其定價對於中小型專案來說可能過於昂貴: 方面 Apryse PDF(PDFTron) IronPDF 起價 據報道,每位開發商每年需支付 1500 美元以上。 一次性支付 749 美元(精簡版) 許可模式 年度訂閱 永久許可 查看器許可證 另行收費 不適用(請使用標準檢視器) 伺服器許可證 企業定價要求 包含在許可證等級中 三年總成本 每位開發商 4,500 美元以上 一次性支付 749 美元 整合的複雜性 Apryse PDF 的 C++ 淵源引入了複雜性,影響了開發速度: 特徵 Apryse PDF IronPDF 設定 模組路徑、外部二進位文件 單一 NuGet 套件 初始化 PDFNet.Initialize()附有許可證 簡單屬性賦值 HTML渲染 需要外部 html2pdf 模組 內建鉻合金引擎 API 風格 C++ 傳承,複雜 現代 C# 約定 依賴關係 多個 DLL,平台特定 自包含包裝 何時考慮移民 如果符合以下條件,請遷移到 IronPDF: 您主要需要將 HTML/URL 轉換為 PDF。 你想要更簡潔、樣板程式碼更少的 API 您的使用情境不適用高價策略 您不需要 PDFViewCtrl 檢視器控件 您更傾向於一次性授權而非訂閱。 如果您符合以下條件,請繼續使用 Apryse PDF: 您需要使用它們的本機檢視器控制項(PDFViewCtrl)。 您大量使用 XOD 或專有格式 您需要特定的企業功能(進階編輯等) 您的組織已擁有企業授權。 遷移前準備 先決條件 請確保您的環境符合以下要求: .NET Framework 4.6.2+ 或 .NET Core 3.1 / .NET 5-9 Visual Studio 2019+ 或帶有 C# 擴充功能的 VS Code NuGet 套件管理器訪問 IronPDF 許可證金鑰(可在ironpdf.com提供免費試用) 審核 Apryse PDF 使用情況 在解決方案目錄中執行以下命令,以識別所有 Apryse 引用: # Find all pdftron using statements grep -r "using pdftron" --include="*.cs" . # Find PDFNet initialization grep -r "PDFNet.Initialize\|PDFNet.SetResourcesPath" --include="*.cs" . # Find PDFDoc usage grep -r "new PDFDoc\|PDFDoc\." --include="*.cs" . # Find HTML2PDF usage grep -r "HTML2PDF\|InsertFromURL\|InsertFromHtmlString" --include="*.cs" . # Find ElementReader/Writer usage grep -r "ElementReader\|ElementWriter\|ElementBuilder" --include="*.cs" . # Find all pdftron using statements grep -r "using pdftron" --include="*.cs" . # Find PDFNet initialization grep -r "PDFNet.Initialize\|PDFNet.SetResourcesPath" --include="*.cs" . # Find PDFDoc usage grep -r "new PDFDoc\|PDFDoc\." --include="*.cs" . # Find HTML2PDF usage grep -r "HTML2PDF\|InsertFromURL\|InsertFromHtmlString" --include="*.cs" . # Find ElementReader/Writer usage grep -r "ElementReader\|ElementWriter\|ElementBuilder" --include="*.cs" . SHELL 需要預見的重大變化 Apryse PDF 圖案 需要更改 PDFNet.Initialize() 替換為IronPdf.License.LicenseKey HTML2PDF模組 內建ChromePdfRenderer ElementReader / ElementWriter IronPDF在內部處理內容 SDFDoc.SaveOptions 簡單的SaveAs()方法 PDFViewCtrl 使用外部PDF閱讀器 XOD格式 轉換為 PDF 或圖像 模組路徑配置 不需要 逐步遷移過程 步驟 1:更新 NuGet 套件 移除 Apryse/PDFTron 軟體包,並安裝 IronPDF: # Remove Apryse/PDFTron packages dotnet remove package PDFTron.NET.x64 dotnet remove package PDFTron.NET.x86 dotnet remove package pdftron # Install IronPDF dotnet add package IronPdf # Remove Apryse/PDFTron packages dotnet remove package PDFTron.NET.x64 dotnet remove package PDFTron.NET.x86 dotnet remove package pdftron # Install IronPDF dotnet add package IronPdf SHELL 或透過軟體包管理器控制台: Uninstall-Package PDFTron.NET.x64 Install-Package IronPdf 步驟 2:更新命名空間引用 將 Apryse 命名空間替換為 IronPDF: // Remove these using pdftron; using pdftron.PDF; using pdftron.PDF.Convert; using pdftron.SDF; using pdftron.Filters; // Add these using IronPdf; using IronPdf.Rendering; // Remove these using pdftron; using pdftron.PDF; using pdftron.PDF.Convert; using pdftron.SDF; using pdftron.Filters; // Add these using IronPdf; using IronPdf.Rendering; $vbLabelText $csharpLabel 步驟 3:移除初始化樣板 Apryse PDF 需要複雜的初始化過程。 IronPDF 完全消除了這個問題。 Apryse PDF實作: // Complex initialization PDFNet.Initialize("YOUR_LICENSE_KEY"); PDFNet.SetResourcesPath("path/to/resources"); // Plus module path for HTML2PDF... // Complex initialization PDFNet.Initialize("YOUR_LICENSE_KEY"); PDFNet.SetResourcesPath("path/to/resources"); // Plus module path for HTML2PDF... $vbLabelText $csharpLabel IronPDF實現: // Simple license assignment (optional for development) IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"; // Simple license assignment (optional for development) IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"; $vbLabelText $csharpLabel 使用 IronPDF 不需要呼叫PDFNet.Terminate() -資源會自動管理。 完整的 API 遷移參考 核心類別映射 Apryse PDF 課程 IronPDF當量 筆記 PDFDoc PdfDocument 主文檔類 HTML2PDF ChromePdfRenderer HTML 轉 PDF TextExtractor PdfDocument.ExtractAllText() 文字擷取 Stamper PdfDocument.ApplyWatermark() 水印和印章 PDFDraw PdfDocument.ToBitmap() 柵格化 SecurityHandler PdfDocument.SecuritySettings 加密/密碼 PDFNet IronPdf.License 授權和配置 文檔操作 Apryse PDF 方法 IronPDF 方法 筆記 new PDFDoc() new PdfDocument() 空白文檔 new PDFDoc(path) PdfDocument.FromFile(path) 從檔案載入 new PDFDoc(buffer) PdfDocument.FromBinaryData(bytes) 從位元組加載 doc.Save(path, options) pdf.SaveAs(path) 儲存到文件 doc.Save(buffer) pdf.BinaryData 取得位元組 doc.Close() pdf.Dispose() 清理(或using ) doc.GetPageCount() pdf.PageCount 頁數 doc.AppendPages(doc2, start, end) PdfDocument.Merge(pdfs) 合併文檔 HTML 轉 PDF Apryse PDF 方法 IronPDF 方法 筆記 HTML2PDF.Convert(doc) renderer.RenderHtmlAsPdf(html) 返回 PDF 文檔 converter.InsertFromURL(url) renderer.RenderUrlAsPdf(url) URL轉換 converter.InsertFromHtmlString(html) renderer.RenderHtmlAsPdf(html) HTML字串 converter.SetModulePath(path) 不需要 內置發動機 converter.SetPaperSize(width, height) RenderingOptions.PaperSize 紙張尺寸 converter.SetLandscape(true) RenderingOptions.PaperOrientation 方向 程式碼遷移範例 轉換為 PDF 的 HTML 字串 最常見的操作反映了樣板程式碼的大幅減少。 Apryse PDF實作: using pdftron; using pdftron.PDF; class Program { static void Main() { PDFNet.Initialize("YOUR_LICENSE_KEY"); PDFNet.SetResourcesPath("path/to/resources"); string html = "<html><body><h1>Hello World</h1><p>Content here</p></body></html>"; using (PDFDoc doc = new PDFDoc()) { HTML2PDF converter = new HTML2PDF(); converter.SetModulePath("path/to/html2pdf"); converter.InsertFromHtmlString(html); HTML2PDF.WebPageSettings settings = new HTML2PDF.WebPageSettings(); settings.SetPrintBackground(true); settings.SetLoadImages(true); if (converter.Convert(doc)) { doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized); Console.WriteLine("PDF created successfully"); } else { Console.WriteLine($"Conversion failed: {converter.GetLog()}"); } } PDFNet.Terminate(); } } using pdftron; using pdftron.PDF; class Program { static void Main() { PDFNet.Initialize("YOUR_LICENSE_KEY"); PDFNet.SetResourcesPath("path/to/resources"); string html = "<html><body><h1>Hello World</h1><p>Content here</p></body></html>"; using (PDFDoc doc = new PDFDoc()) { HTML2PDF converter = new HTML2PDF(); converter.SetModulePath("path/to/html2pdf"); converter.InsertFromHtmlString(html); HTML2PDF.WebPageSettings settings = new HTML2PDF.WebPageSettings(); settings.SetPrintBackground(true); settings.SetLoadImages(true); if (converter.Convert(doc)) { doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized); Console.WriteLine("PDF created successfully"); } else { Console.WriteLine($"Conversion failed: {converter.GetLog()}"); } } PDFNet.Terminate(); } } $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); string html = "<html><body><h1>Hello World</h1></body></html>"; var pdf = renderer.RenderHtmlAsPdf(html); pdf.SaveAs("output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); string html = "<html><body><h1>Hello World</h1></body></html>"; var pdf = renderer.RenderHtmlAsPdf(html); pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel IronPDF 消除了初始化、模組路徑和清理程式碼,將 35 行以上的程式碼減少到 5 行。 URL 轉 PDF Apryse PDF實作: using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc()) { HTML2PDF converter = new HTML2PDF(); converter.SetModulePath("path/to/html2pdf"); HTML2PDF.WebPageSettings settings = new HTML2PDF.WebPageSettings(); settings.SetLoadImages(true); settings.SetAllowJavaScript(true); settings.SetPrintBackground(true); converter.InsertFromURL("https://example.com", settings); if (converter.Convert(doc)) { doc.Save("webpage.pdf", SDFDoc.SaveOptions.e_linearized); } } PDFNet.Terminate(); using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc()) { HTML2PDF converter = new HTML2PDF(); converter.SetModulePath("path/to/html2pdf"); HTML2PDF.WebPageSettings settings = new HTML2PDF.WebPageSettings(); settings.SetLoadImages(true); settings.SetAllowJavaScript(true); settings.SetPrintBackground(true); converter.InsertFromURL("https://example.com", settings); if (converter.Convert(doc)) { doc.Save("webpage.pdf", SDFDoc.SaveOptions.e_linearized); } } PDFNet.Terminate(); $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); string url = "https://www.example.com"; var pdf = renderer.RenderUrlAsPdf(url); pdf.SaveAs("webpage.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); string url = "https://www.example.com"; var pdf = renderer.RenderUrlAsPdf(url); pdf.SaveAs("webpage.pdf"); } } $vbLabelText $csharpLabel 合併多個PDF文件 Apryse PDF實作: using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc mainDoc = new PDFDoc()) { string[] files = { "doc1.pdf", "doc2.pdf", "doc3.pdf" }; foreach (string file in files) { using (PDFDoc doc = new PDFDoc(file)) { mainDoc.AppendPages(doc, 1, doc.GetPageCount()); } } mainDoc.Save("merged.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc mainDoc = new PDFDoc()) { string[] files = { "doc1.pdf", "doc2.pdf", "doc3.pdf" }; foreach (string file in files) { using (PDFDoc doc = new PDFDoc(file)) { mainDoc.AppendPages(doc, 1, doc.GetPageCount()); } } mainDoc.Save("merged.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class Program { static void Main() { var pdf1 = PdfDocument.FromFile("document1.pdf"); var pdf2 = PdfDocument.FromFile("document2.pdf"); var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 }); merged.SaveAs("merged.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class Program { static void Main() { var pdf1 = PdfDocument.FromFile("document1.pdf"); var pdf2 = PdfDocument.FromFile("document2.pdf"); var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 }); merged.SaveAs("merged.pdf"); } } $vbLabelText $csharpLabel IronPDF 的靜態Merge方法直接接受多個文檔,消除了頁面迭代模式。 文字擷取 Apryse PDF實作: using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { TextExtractor extractor = new TextExtractor(); for (int i = 1; i <= doc.GetPageCount(); i++) { Page page = doc.GetPage(i); extractor.Begin(page); string pageText = extractor.GetAsText(); Console.WriteLine($"Page {i}:"); Console.WriteLine(pageText); } } PDFNet.Terminate(); using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { TextExtractor extractor = new TextExtractor(); for (int i = 1; i <= doc.GetPageCount(); i++) { Page page = doc.GetPage(i); extractor.Begin(page); string pageText = extractor.GetAsText(); Console.WriteLine($"Page {i}:"); Console.WriteLine(pageText); } } PDFNet.Terminate(); $vbLabelText $csharpLabel IronPDF實現: using IronPdf; var pdf = PdfDocument.FromFile("document.pdf"); // Extract all text at once string allText = pdf.ExtractAllText(); Console.WriteLine(allText); // Extract from specific page string page1Text = pdf.ExtractTextFromPage(0); // 0-indexed Console.WriteLine($"Page 1: {page1Text}"); using IronPdf; var pdf = PdfDocument.FromFile("document.pdf"); // Extract all text at once string allText = pdf.ExtractAllText(); Console.WriteLine(allText); // Extract from specific page string page1Text = pdf.ExtractTextFromPage(0); // 0-indexed Console.WriteLine($"Page 1: {page1Text}"); $vbLabelText $csharpLabel 添加浮水印 Apryse PDF實作: using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { Stamper stamper = new Stamper(Stamper.SizeType.e_relative_scale, 0.5, 0.5); stamper.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_center); stamper.SetOpacity(0.3); stamper.SetRotation(45); stamper.SetFontColor(new ColorPt(1, 0, 0)); stamper.SetTextAlignment(Stamper.TextAlignment.e_align_center); stamper.StampText(doc, "CONFIDENTIAL", new PageSet(1, doc.GetPageCount())); doc.Save("watermarked.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); using pdftron; using pdftron.PDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { Stamper stamper = new Stamper(Stamper.SizeType.e_relative_scale, 0.5, 0.5); stamper.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_center); stamper.SetOpacity(0.3); stamper.SetRotation(45); stamper.SetFontColor(new ColorPt(1, 0, 0)); stamper.SetTextAlignment(Stamper.TextAlignment.e_align_center); stamper.StampText(doc, "CONFIDENTIAL", new PageSet(1, doc.GetPageCount())); doc.Save("watermarked.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); $vbLabelText $csharpLabel IronPDF實現: using IronPdf; using IronPdf.Editing; var pdf = PdfDocument.FromFile("document.pdf"); // HTML-based watermark with full styling control string watermarkHtml = @" <div style=' color: red; opacity: 0.3; font-size: 72px; font-weight: bold; text-align: center; '>CONFIDENTIAL</div>"; pdf.ApplyWatermark(watermarkHtml, rotation: 45, verticalAlignment: VerticalAlignment.Middle, horizontalAlignment: HorizontalAlignment.Center); pdf.SaveAs("watermarked.pdf"); using IronPdf; using IronPdf.Editing; var pdf = PdfDocument.FromFile("document.pdf"); // HTML-based watermark with full styling control string watermarkHtml = @" <div style=' color: red; opacity: 0.3; font-size: 72px; font-weight: bold; text-align: center; '>CONFIDENTIAL</div>"; pdf.ApplyWatermark(watermarkHtml, rotation: 45, verticalAlignment: VerticalAlignment.Middle, horizontalAlignment: HorizontalAlignment.Center); pdf.SaveAs("watermarked.pdf"); $vbLabelText $csharpLabel IronPDF 使用基於 HTML/CSS 的浮水印技術,透過熟悉的 Web 技術提供完整的樣式控制。 密碼保護 Apryse PDF實作: using pdftron; using pdftron.PDF; using pdftron.SDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { SecurityHandler handler = new SecurityHandler(); handler.ChangeUserPassword("user123"); handler.ChangeMasterPassword("owner456"); handler.SetPermission(SecurityHandler.Permission.e_print, false); handler.SetPermission(SecurityHandler.Permission.e_extract_content, false); doc.SetSecurityHandler(handler); doc.Save("protected.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); using pdftron; using pdftron.PDF; using pdftron.SDF; PDFNet.Initialize("YOUR_LICENSE_KEY"); using (PDFDoc doc = new PDFDoc("document.pdf")) { SecurityHandler handler = new SecurityHandler(); handler.ChangeUserPassword("user123"); handler.ChangeMasterPassword("owner456"); handler.SetPermission(SecurityHandler.Permission.e_print, false); handler.SetPermission(SecurityHandler.Permission.e_extract_content, false); doc.SetSecurityHandler(handler); doc.Save("protected.pdf", SDFDoc.SaveOptions.e_linearized); } PDFNet.Terminate(); $vbLabelText $csharpLabel IronPDF實現: using IronPdf; var pdf = PdfDocument.FromFile("document.pdf"); // Set passwords pdf.SecuritySettings.UserPassword = "user123"; pdf.SecuritySettings.OwnerPassword = "owner456"; // Set permissions pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint; pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit; pdf.SaveAs("protected.pdf"); using IronPdf; var pdf = PdfDocument.FromFile("document.pdf"); // Set passwords pdf.SecuritySettings.UserPassword = "user123"; pdf.SecuritySettings.OwnerPassword = "owner456"; // Set permissions pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint; pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit; pdf.SaveAs("protected.pdf"); $vbLabelText $csharpLabel 頁首和頁尾 IronPDF實現: using IronPdf; var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter { HtmlFragment = "<div style='text-align:center; font-size:12px;'>Company Header</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;'>Company Header</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"); $vbLabelText $csharpLabel IronPDF 支援使用{page}和{total-pages}等佔位符號標記進行動態頁碼編號。 更多選項請參閱頁首和頁尾文件。 ASP.NET Core 集成 Apryse PDF 的初始化要求使 Web 應用程式整合變得複雜。 IronPDF簡化了這種模式。 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.Stream, "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.Stream, "application/pdf", "report.pdf"); } } $vbLabelText $csharpLabel 依賴注入配置 // Program.cs public void ConfigureServices(IServiceCollection services) { // Set license once IronPdf.License.LicenseKey = Configuration["IronPdf:LicenseKey"]; // Register renderer as scoped service services.AddScoped<ChromePdfRenderer>(); // Or create a wrapper service services.AddScoped<IPdfService, IronPdfService>(); } // IronPdfService.cs public class IronPdfService : IPdfService { private readonly ChromePdfRenderer _renderer; public IronPdfService() { _renderer = new ChromePdfRenderer(); _renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; _renderer.RenderingOptions.PrintHtmlBackgrounds = true; } public PdfDocument GenerateFromHtml(string html) => _renderer.RenderHtmlAsPdf(html); public Task<PdfDocument> GenerateFromHtmlAsync(string html) => _renderer.RenderHtmlAsPdfAsync(html); } // Program.cs public void ConfigureServices(IServiceCollection services) { // Set license once IronPdf.License.LicenseKey = Configuration["IronPdf:LicenseKey"]; // Register renderer as scoped service services.AddScoped<ChromePdfRenderer>(); // Or create a wrapper service services.AddScoped<IPdfService, IronPdfService>(); } // IronPdfService.cs public class IronPdfService : IPdfService { private readonly ChromePdfRenderer _renderer; public IronPdfService() { _renderer = new ChromePdfRenderer(); _renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; _renderer.RenderingOptions.PrintHtmlBackgrounds = true; } public PdfDocument GenerateFromHtml(string html) => _renderer.RenderHtmlAsPdf(html); public Task<PdfDocument> GenerateFromHtmlAsync(string html) => _renderer.RenderHtmlAsPdfAsync(html); } $vbLabelText $csharpLabel 效能比較 指標 Apryse PDF IronPDF 冷啟動 快速(原生程式碼) ~2秒(鉻初始) 後續渲染 快速地 快速地 複雜的 HTML 變數(html2pdf 模組) 極佳(鉻) CSS 支援 有限的 完整的 CSS3 JavaScript 有限的 全力支持 效能優化技巧 // 1. Reuse renderer instance private static readonly ChromePdfRenderer SharedRenderer = new ChromePdfRenderer(); // 2. Disable unnecessary features for speed var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.EnableJavaScript = false; // If not needed renderer.RenderingOptions.WaitFor.RenderDelay(0); // No delay renderer.RenderingOptions.Timeout = 30000; // 30s max // 3. Proper disposal using (var pdf = renderer.RenderHtmlAsPdf(html)) { pdf.SaveAs("output.pdf"); } // 1. Reuse renderer instance private static readonly ChromePdfRenderer SharedRenderer = new ChromePdfRenderer(); // 2. Disable unnecessary features for speed var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.EnableJavaScript = false; // If not needed renderer.RenderingOptions.WaitFor.RenderDelay(0); // No delay renderer.RenderingOptions.Timeout = 30000; // 30s max // 3. Proper disposal using (var pdf = renderer.RenderHtmlAsPdf(html)) { pdf.SaveAs("output.pdf"); } $vbLabelText $csharpLabel 解決常見遷移問題 問題:模組路徑錯誤 移除所有模組路徑配置-IronPDF 的 Chromium 引擎是內建的: // Remove this converter.SetModulePath("path/to/html2pdf"); // Just use the renderer var renderer = new ChromePdfRenderer(); // Remove this converter.SetModulePath("path/to/html2pdf"); // Just use the renderer var renderer = new ChromePdfRenderer(); $vbLabelText $csharpLabel 問題:未找到 PDFNet.Initialize() 替換為 IronPDF 許可證設定: // Remove this PDFNet.Initialize("KEY"); PDFNet.SetResourcesPath("path"); // Use this (optional for development) IronPdf.License.LicenseKey = "YOUR-KEY"; // Remove this PDFNet.Initialize("KEY"); PDFNet.SetResourcesPath("path"); // Use this (optional for development) IronPdf.License.LicenseKey = "YOUR-KEY"; $vbLabelText $csharpLabel 問題:PDFViewCtrl 替換 IronPDF 不包含檢視器控制項。 選項: 使用 PDF.js 為網頁檢視器提供 PDF 版本。 使用系統內附的 PDF 檢視器。 考慮第三方檢視器元件 遷移後檢查清單 程式碼遷移完成後,請驗證以下內容: 驗證 PDF 輸出品質是否符合預期 測試所有極端情況(大型文件、複雜的 CSS) 比較性能指標 如果需要,更新 Docker 配置 移除 Apryse 授權及相關配置 記錄所有 IronPDF 特有的配置 訓練團隊掌握新的 API 模式 如有需要,更新 CI/CD 管線 讓您的 PDF 基礎架構面向未來 隨著 .NET 10 即將到來,C# 14 也引入了新的語言特性,選擇一個具有現代約定的原生 .NET PDF 庫可以確保與不斷發展的運行時功能相容。 IronPDF 致力於支援最新的 .NET 版本,這意味著隨著專案擴展到 2025 年和 2026 年,您的遷移投資將獲得回報——無需每年續訂訂閱。 其他資源 IronPDF 文件 HTML 轉 PDF 教學課程 API 參考 NuGet 套件 -授權選項 從 Apryse PDF 遷移到 IronPDF 會將您的 PDF 程式碼庫從複雜的 C++ 模式轉換為道地的 C# 模式。 消除初始化樣板程式碼、模組路徑配置和基於訂閱的許可,可以立即提高生產力,同時降低長期成本。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 發表日期 2026年2月1日 How to Migrate from ZetPDF to IronPDF in C# Master the migration from ZetPDF to IronPDF with this complete C# guide. Switch from a coordinate-based library to a modern HTML-to-PDF solution. Includes code examples for HTML conversion, merging PDFs, and removing PDFSharp dependencies. 閱讀更多 發表日期 2026年2月1日 How to Migrate from Scryber.Core to IronPDF in C# Master the migration from Scryber.Core to IronPDF with this complete C# guide. Switch from custom XML/HTML parsing to a modern Chromium renderer. Includes code examples for HTML conversion, URL rendering, and replacing proprietary bindings. 閱讀更多 發表日期 2026年2月1日 How to Migrate from XFINIUM.PDF to IronPDF in C# Master the migration from XFINIUM.PDF to IronPDF with this complete C# guide. Switch from manual coordinate-based positioning to declarative HTML/CSS rendering. Includes code examples for replacing graphics primitives and automatic layout. 閱讀更多 How to Migrate from Aspose.PDF to IronPDF in C#How to Migrate from Api2pdf to Iron...
發表日期 2026年2月1日 How to Migrate from ZetPDF to IronPDF in C# Master the migration from ZetPDF to IronPDF with this complete C# guide. Switch from a coordinate-based library to a modern HTML-to-PDF solution. Includes code examples for HTML conversion, merging PDFs, and removing PDFSharp dependencies. 閱讀更多
發表日期 2026年2月1日 How to Migrate from Scryber.Core to IronPDF in C# Master the migration from Scryber.Core to IronPDF with this complete C# guide. Switch from custom XML/HTML parsing to a modern Chromium renderer. Includes code examples for HTML conversion, URL rendering, and replacing proprietary bindings. 閱讀更多
發表日期 2026年2月1日 How to Migrate from XFINIUM.PDF to IronPDF in C# Master the migration from XFINIUM.PDF to IronPDF with this complete C# guide. Switch from manual coordinate-based positioning to declarative HTML/CSS rendering. Includes code examples for replacing graphics primitives and automatic layout. 閱讀更多