MIGRATION GUIDES How to Migrate from Ghostscript GPL to IronPDF in C# Curtis Chau 發表日期:2026年1月25日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 從 Ghostscript GPL 遷移到 IronPDF 會將您的 .NET PDF 工作流程從命令列進程產生和基於字串的開關操作轉變為類型安全的、支援 IntelliSense 的原生 .NET API。 本指南為專業的 .NET 開發人員提供了一個全面的、逐步的遷移路徑,消除了 AGPL 許可問題和外部二元依賴項。 為什麼要從 Ghostscript GPL 遷移到 IronPDF Ghostscript GPL挑戰賽 Ghostscript GPL 是一款歷史悠久的 PostScript/PDF 解釋器,但將其用於現代 .NET 應用程式面臨著重大挑戰: AGPL 授權限制: Ghostscript GPL 的 AGPL 授權要求,如果您散佈使用該授權的軟體,則必須發佈您的原始程式碼——除非您從 Artifex 購買昂貴的商業授權。 這種"病毒式"授權模式會為專有應用程式帶來重大的法律風險。 2.命令列介面: Ghostscript GPL 本質上就是一個命令列工具。 從 C# 中使用它需要產生進程、傳遞字串參數和解析輸出——這是一種脆弱且容易出錯的方法。 3.外部二進位依賴項:您必須單獨安裝 Ghostscript GPL,管理 PATH 變量,並確保跨部署環境的版本相容性。 32 位元和 64 位元系統需要不同的 DLL 檔案( gsdll32.dll與gsdll64.dll )。 4.不支援原生 HTML 轉 PDF: Ghostscript GPL 無法直接將 HTML 轉換為 PDF。 您需要先使用另一個工具將 HTML 轉換為 PostScript,然後使用 Ghostscript GPL 將 PostScript 轉換為 PDF——這是一個具有外部相依性的多步驟流程。 5.複雜的開關語法:操作透過晦澀難懂的命令列開關進行控制,例如-dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=... 。 沒有智慧感知功能,沒有輸入安全功能,容易輸錯字。 6.錯誤處理:錯誤以文字字串的形式透過 stderr 輸出,需要進行解析而不是結構化的異常處理。 7.進程管理開銷:每個操作都會產生一個單獨的進程,這增加了錯誤處理、逾時和資源清理的開銷和複雜性。 Ghostscript GPL 與 IronPDF 的比較 方面 Ghostscript GPL IronPDF 執照 AGPL(病毒式傳播)或昂貴的商業用途 商業條款清晰明了。 一體化 命令列進程生成 原生 .NET 函式庫 API設計 基於字串的開關 類型化、支援 IntelliSense 的 API 錯誤處理 解析 stderr 文本 .NET 異常 HTML 轉 PDF 不支援(需要外部工具) 內建鉻合金引擎 依賴關係 外部二進位安裝 自包含的 NuGet 套件 部署 配置 PATH 環境變量,複製 DLL 文件 只需加入 NuGet 引用即可 螺紋安全 僅過程隔離 螺紋安全設計 近代 .NET 支持有限 完全支援 .NET 6/7/8/9/10 非同步支援 基於流程 原生 async/await 對於計劃在 2025 年和 2026 年採用 .NET 10 和 C# 14 的團隊,IronPDF 提供了一個面向未來的基礎,可以與現代 .NET 模式原生整合。 遷移複雜度評估 各功能預計工作量 特徵 遷移複雜性 筆記 PDF 轉影像 低的 直接 API 映射 合併PDF 低的 IronPDF 讓一切變得更簡單 壓縮 PDF 低的 內建選項 PDF優化 低的 不同的方法 加密 中等的 不同的API 頁面擷取 低的 0索引與1索引 PostScript 轉 PDF 中高 首先將 PS 文件轉換為 PDF 文件 客製化開關 中高 研究等效特徵 範式轉移 Ghostscript GPL 遷移的根本轉變在於從命令列程序執行轉變為類型化的 .NET API 呼叫: Ghostscript GPL:"將這些字串開關傳遞給外部程序" IronPDF:"在 .NET 物件上呼叫這些方法" 開始之前 先決條件 .NET 版本: IronPDF 支援 .NET Framework 4.6.2+ 和 .NET Core 2.0+ / .NET 5/6/7/8/9+ 2.許可證密鑰:從ironpdf.com取得您的 IronPDF 許可證密鑰。 3.備份:建立一個用於遷移工作的分支 識別所有 Ghostscript GPL 使用情況 # Find all Ghostscript.NET references grep -r "Ghostscript\.NET\|GhostscriptProcessor\|GhostscriptRasterizer\|gsdll" --include="*.cs" . # Find direct process calls to Ghostscript grep -r "gswin64c\|gswin32c\|gs\|ProcessStartInfo.*ghost" --include="*.cs" . # Find package references grep -r "Ghostscript" --include="*.csproj" . # Find all Ghostscript.NET references grep -r "Ghostscript\.NET\|GhostscriptProcessor\|GhostscriptRasterizer\|gsdll" --include="*.cs" . # Find direct process calls to Ghostscript grep -r "gswin64c\|gswin32c\|gs\|ProcessStartInfo.*ghost" --include="*.cs" . # Find package references grep -r "Ghostscript" --include="*.csproj" . SHELL NuGet 套件變更 # Remove Ghostscript.NET dotnet remove package Ghostscript.NET # Install IronPDF dotnet add package IronPdf # Remove Ghostscript.NET dotnet remove package Ghostscript.NET # Install IronPDF dotnet add package IronPdf SHELL 移除 Ghostscript GPL 依賴項 遷移後: 從伺服器卸載 Ghostscript GPL 從部署移除gsdll32.dll / gsdll64.dll 移除 Ghostscript GPL 的 PATH 配置 刪除所有GhostscriptVersionInfo引用 快速入門遷移 步驟 1:更新許可證配置 之前(Ghostscript GPL): Ghostscript GPL 根據 AGPL 要求要么公開原始程式碼,要么從 Artifex 購買昂貴的商業許可證。 (IronPDF 之後): // Set once at application startup IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY"; // Set once at application startup IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY"; $vbLabelText $csharpLabel 步驟 2:更新命名空間導入 // Before (Ghostscript GPL) using Ghostscript.NET; using Ghostscript.NET.Processor; using Ghostscript.NET.Rasterizer; // After (IronPDF) using IronPdf; // Before (Ghostscript GPL) using Ghostscript.NET; using Ghostscript.NET.Processor; using Ghostscript.NET.Rasterizer; // After (IronPDF) using IronPdf; $vbLabelText $csharpLabel 完整 API 參考 核心類別映射 Ghostscript.NET IronPDF 描述 GhostscriptProcessor 各種PdfDocument方法 PDF處理 GhostscriptRasterizer PdfDocument.ToBitmap() / RasterizeToImageFiles() PDF 轉影像 GhostscriptVersionInfo 不適用(無需填寫) DLL 位置 GhostscriptStdIO 不適用(可使用例外情況) I/O 處理 進程 + 命令列 ChromePdfRenderer HTML 轉 PDF 命令列交換器映射 Ghostscript GPL 開關 IronPDF當量 描述 -dNOPAUSE 不適用(無需填寫) 不要在翻頁之間停頓 -dBATCH 不適用(無需填寫) 處理完畢後退出 -dSAFER 不適用(預設值) 安全文件訪問 -sDEVICE=pdfwrite 各種PDF方法 輸出 PDF -sDEVICE=png16m ToBitmap()或RasterizeToImageFiles() PNG 輸出 -sOutputFile=X SaveAs("X") 輸出檔名 -r300 方法中的 DPI 參數 解決 -dPDFSETTINGS=/ebook CompressImages(quality: 75) 中等品質 -sOwnerPassword=X SecuritySettings.OwnerPassword 所有者密碼 -sUserPassword=X SecuritySettings.UserPassword 使用者密碼 程式碼遷移範例 範例 1:HTML 轉 PDF 之前(Ghostscript GPL): // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Processor; using System.IO; using System.Text; class GhostscriptExample { static void Main() { // Ghostscript cannot directly convert HTML to PDF // You need to first convert HTML to PS/EPS using another tool // then use Ghostscript to convert PS to PDF string htmlContent = "<html><body><h1>Hello World</h1></body></html>"; string psFile = "temp.ps"; string outputPdf = "output.pdf"; // This is a workaround - Ghostscript primarily works with PostScript GhostscriptProcessor processor = new GhostscriptProcessor(); List<string> switches = new List<string> { "-dNOPAUSE", "-dBATCH", "-dSAFER", "-sDEVICE=pdfwrite", $"-sOutputFile={outputPdf}", psFile }; processor.Process(switches.ToArray()); } } // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Processor; using System.IO; using System.Text; class GhostscriptExample { static void Main() { // Ghostscript cannot directly convert HTML to PDF // You need to first convert HTML to PS/EPS using another tool // then use Ghostscript to convert PS to PDF string htmlContent = "<html><body><h1>Hello World</h1></body></html>"; string psFile = "temp.ps"; string outputPdf = "output.pdf"; // This is a workaround - Ghostscript primarily works with PostScript GhostscriptProcessor processor = new GhostscriptProcessor(); List<string> switches = new List<string> { "-dNOPAUSE", "-dBATCH", "-dSAFER", "-sDEVICE=pdfwrite", $"-sOutputFile={outputPdf}", psFile }; processor.Process(switches.ToArray()); } } $vbLabelText $csharpLabel (IronPDF 之後): // NuGet: Install-Package IronPdf using IronPdf; class IronPdfExample { static void Main() { var renderer = new ChromePdfRenderer(); string htmlContent = "<html><body><h1>Hello World</h1></body></html>"; var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs("output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; class IronPdfExample { static void Main() { var renderer = new ChromePdfRenderer(); string htmlContent = "<html><body><h1>Hello World</h1></body></html>"; var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel 差異很明顯:Ghostscript GPL 根本無法直接將 HTML 轉換為 PDF——它需要使用外部工具進行中間 PostScript 轉換。 IronPDF 的ChromePdfRenderer提供直接的 HTML 到 PDF 轉換,並完全支援 CSS3、JavaScript 和現代 Web 標準。 如需更多渲染選項,請參閱HTML 轉 PDF 文件。 範例 2:PDF 轉影像 之前(Ghostscript GPL): // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Rasterizer; using System.Drawing; using System.Drawing.Imaging; using System.IO; class GhostscriptExample { static void Main() { string inputPdf = "input.pdf"; string outputPath = "output"; GhostscriptVersionInfo gvi = new GhostscriptVersionInfo("gsdll64.dll"); using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer()) { rasterizer.Open(inputPdf, gvi, false); for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++) { Image img = rasterizer.GetPage(300, pageNumber); img.Save($"{outputPath}_page{pageNumber}.png", ImageFormat.Png); img.Dispose(); } } } } // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Rasterizer; using System.Drawing; using System.Drawing.Imaging; using System.IO; class GhostscriptExample { static void Main() { string inputPdf = "input.pdf"; string outputPath = "output"; GhostscriptVersionInfo gvi = new GhostscriptVersionInfo("gsdll64.dll"); using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer()) { rasterizer.Open(inputPdf, gvi, false); for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++) { Image img = rasterizer.GetPage(300, pageNumber); img.Save($"{outputPath}_page{pageNumber}.png", ImageFormat.Png); img.Dispose(); } } } } $vbLabelText $csharpLabel (IronPDF 之後): // NuGet: Install-Package IronPdf using IronPdf; using System; class IronPdfExample { static void Main() { var pdf = PdfDocument.FromFile("input.pdf"); var images = pdf.ToBitmap(); for (int i = 0; i < images.Length; i++) { images[i].Save($"output_page{i + 1}.png"); } } } // NuGet: Install-Package IronPdf using IronPdf; using System; class IronPdfExample { static void Main() { var pdf = PdfDocument.FromFile("input.pdf"); var images = pdf.ToBitmap(); for (int i = 0; i < images.Length; i++) { images[i].Save($"output_page{i + 1}.png"); } } } $vbLabelText $csharpLabel Ghostscript GPL 方法需要找到外部gsdll64.dll ,建立一個GhostscriptVersionInfo對象,並使用從 1 開始的頁碼。 IronPDF 的ToBitmap()方法提供了一個簡潔的單行方法,沒有任何外部相依性。 請注意頁面索引的差異:Ghostscript GPL 使用索引為 1 的頁面,而 IronPDF 使用索引為 0 的頁面(標準的 .NET 約定)。 範例 3:合併 PDF 文件 之前(Ghostscript GPL): // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Processor; using System.Collections.Generic; class GhostscriptExample { static void Main() { string outputPdf = "merged.pdf"; string[] inputFiles = { "file1.pdf", "file2.pdf", "file3.pdf" }; GhostscriptProcessor processor = new GhostscriptProcessor(); List<string> switches = new List<string> { "-dNOPAUSE", "-dBATCH", "-dSAFER", "-sDEVICE=pdfwrite", $"-sOutputFile={outputPdf}" }; switches.AddRange(inputFiles); processor.Process(switches.ToArray()); } } // NuGet: Install-Package Ghostscript.NET using Ghostscript.NET; using Ghostscript.NET.Processor; using System.Collections.Generic; class GhostscriptExample { static void Main() { string outputPdf = "merged.pdf"; string[] inputFiles = { "file1.pdf", "file2.pdf", "file3.pdf" }; GhostscriptProcessor processor = new GhostscriptProcessor(); List<string> switches = new List<string> { "-dNOPAUSE", "-dBATCH", "-dSAFER", "-sDEVICE=pdfwrite", $"-sOutputFile={outputPdf}" }; switches.AddRange(inputFiles); processor.Process(switches.ToArray()); } } $vbLabelText $csharpLabel (IronPDF 之後): // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class IronPdfExample { static void Main() { var pdfs = new List<PdfDocument> { PdfDocument.FromFile("file1.pdf"), PdfDocument.FromFile("file2.pdf"), PdfDocument.FromFile("file3.pdf") }; var merged = PdfDocument.Merge(pdfs); merged.SaveAs("merged.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class IronPdfExample { static void Main() { var pdfs = new List<PdfDocument> { PdfDocument.FromFile("file1.pdf"), PdfDocument.FromFile("file2.pdf"), PdfDocument.FromFile("file3.pdf") }; var merged = PdfDocument.Merge(pdfs); merged.SaveAs("merged.pdf"); } } $vbLabelText $csharpLabel Ghostscript GPL 方法需要記住 switch 語法( -dNOPAUSE 、 -dBATCH 、 -sDEVICE=pdfwrite )並將檔案路徑連接成字串陣列。 IronPDF 的靜態Merge方法提供類型安全、支援 IntelliSense 的合併功能,可合併正確的PdfDocument物件。 了解更多關於合併和拆分PDF的資訊。 關鍵遷移說明 頁面索引轉換 Ghostscript GPL 遷移中最重要的變化之一是頁面索引方式的差異: // Ghostscript GPL: 1-indexed pages for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++) { Image img = rasterizer.GetPage(300, pageNumber); } // IronPDF: 0-indexed pages (standard .NET) for (int i = 0; i < images.Length; i++) { images[i].Save($"output_page{i + 1}.png"); } // Ghostscript GPL: 1-indexed pages for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++) { Image img = rasterizer.GetPage(300, pageNumber); } // IronPDF: 0-indexed pages (standard .NET) for (int i = 0; i < images.Length; i++) { images[i].Save($"output_page{i + 1}.png"); } $vbLabelText $csharpLabel AGPL許可問題消除 Ghostscript GPL 的 AGPL 授權具有"病毒式傳播"的特性,要求在分發應用程式時揭露原始程式碼。 IronPDF的商業許可條款明確,沒有此類要求。 沒有外部二進位文件 IronPDF 是一個完全獨立的系統。 遷移後請刪除這些檔案: gsdll32.dll和gsdll64.dll文件 從伺服器安裝 Ghostscript GPL PATH 環境變數配置 程式碼中的GhostscriptVersionInfo引用 PostScript 文件 IronPDF 不會直接處理 PostScript (.ps) 檔案。 如果您的工作流程需要處理 PostScript 程式碼,則可以: 在 IronPDF 處理之前,先使用其他工具將 PostScript 轉換為 PDF。 將來源內容轉換為 HTML 格式,並使用 IronPDF 的 HTML 渲染功能。 性能考量 沒有進程生成 Ghostscript GPL 操作會產生外部流程,並產生相關的開銷。 IronPDF 在您的 .NET 流程中運作: // Ghostscript GPL: Process spawning overhead processor.Process(switches.ToArray()); // Creates new OS process // IronPDF: In-process execution var merged = PdfDocument.Merge(pdfs); // Native .NET method call // Ghostscript GPL: Process spawning overhead processor.Process(switches.ToArray()); // Creates new OS process // IronPDF: In-process execution var merged = PdfDocument.Merge(pdfs); // Native .NET method call $vbLabelText $csharpLabel 螺紋安全 IronPDF 從設計上就保證了線程安全。 多個線程可以同時使用ChromePdfRenderer和PdfDocument ,而無需擔心同步問題。 遷移清單 遷移前 清點程式碼庫中所有 Ghostscript GPL 的使用情況 記錄目前使用的命令列開關 識別任何 PostScript 處理(需要特殊處理) 審查 AGPL 許可合規性 取得 IronPDF 許可證密鑰 在版本控制系統中建立遷移分支 程式碼遷移 刪除 Ghostscript.NET NuGet 套件: dotnet remove package Ghostscript.NET 安裝 IronPdf NuGet 套件: dotnet add package IronPdf 移除外部 Ghostscript GPL 二進位依賴項 刪除GhostscriptVersionInfo和 DLL 引用 將GhostscriptProcessor.Process()轉換為 IronPDF 方法 將GhostscriptRasterizer轉換為pdf.ToBitmap() 用 API 呼叫取代命令列開關 將錯誤處理方式從解析標準錯誤輸出 (stderr) 改為拋出例外 將以 1 為索引的頁碼轉換為以 0 為索引的頁碼 測試 測試 PDF 轉圖像轉換 測試 PDF 合併 測試頁面擷取 測試壓縮質量 測試密碼保護 驗證輸出品質是否符合預期 效能基準關鍵路徑 部署 從伺服器中移除 Ghostscript GPL 刪除 PATH 配置 從部署中移除gsdll*.dll文件 驗證應用程式在未安裝 Ghostscript GPL 的情況下是否能正常運作 移民後 移除 Ghostscript GPL 許可證(如果是商業用途) 更新文檔 訓練團隊使用 IronPDF API 監控生產過程,發現任何問題 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 Gnostice PDFOne to IronPDF in C#How to Migrate from GemBox PDF to I...
發表日期 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. 閱讀更多