MIGRATION GUIDES How to Migrate from CraftMyPDF 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 上分享 複製連結 電子郵件文章 為什麼要從 CraftMyPDF 遷移到 IronPDF? 像 CraftMyPDF 這樣的基於雲端的 PDF API 引入了一些根本性問題,使得它們不適用於許多生產環境。 基於雲端的PDF API存在的問題 1.您的資料離開您的系統:每個 HTML 範本和 JSON 資料有效負載都會傳送到 CraftMyPDF 的伺服器。 對於發票、合約、醫療記錄或任何敏感的商業數據,這會帶來 HIPAA、GDPR 和 SOC2 合規性風險。 2.網路延遲: CraftMyPDF 自己的文件指出,每個 PDF 需要 1.5-30 秒。 IronPDF可在本地以毫秒速度產生。 3.每個 PDF 的成本累積起來:每月 10,000 個 PDF 按訂閱費率計算會產生大量的經常性成本,而一次性永久許可則不然。 4.針對列印最佳化的輸出:雲端 API 通常會針對列印進行最佳化-減少背景並簡化顏色以節省"墨水"。因此,最終輸出結果與螢幕上顯示的 HTML 程式碼看起來截然不同。 5.模板鎖定: CraftMyPDF 需要使用其專有的拖放編輯器。 你不能隨意使用標準的HTML/CSS。 架構比較 方面 CraftMyPDF IronPDF 數據位置 雲端(您的資料將離開您的系統) 本地部署(資料永不離開) 延遲 每份PDF文件耗時1.5-30秒。 毫秒 定價 按PDF訂閱 一次永久許可 模板系統 僅限專有拖放功能 任何 HTML/CSS/JavaScript 輸出品質 列印優化 像素級精準螢幕渲染 離線工作 否(需要聯網) 是的 遵守 數據離開組織 符合 SOC2/HIPAA 標準 功能對比 特徵 CraftMyPDF IronPDF HTML 轉 PDF 透過 API 模板 ✅ 原生 PDF檔案的URL 透過 API ✅ 原生 自訂模板 僅限專有編輯 ✅ 任何 HTML CSS3 支持 有限的 ✅ 已完成 JavaScript 渲染 有限的 ✅ 已完成 合併/拆分PDF 透過 API ✅ 原生 水印 透過 API ✅ 原生 可離線使用 ❌ ✅ 自託管 ❌ ✅ 遷移前準備 先決條件 請確保您的環境符合以下要求: .NET Framework 4.6.2+ 或 .NET Core 3.1 / .NET 5-9 Visual Studio 2019+ 或帶有 C# 擴充功能的 VS Code NuGet 套件管理器訪問 IronPDF 許可證金鑰(可在ironpdf.com提供免費試用) 審核 CraftMyPDF 使用情況 在解決方案目錄中執行以下命令,以識別所有 CraftMyPDF 引用: # Find all CraftMyPDF usages in your codebase grep -r "CraftMyPdf\|craftmypdf\|api.craftmypdf.com" --include="*.cs" . grep -r "X-API-KEY" --include="*.cs" . # Find API key references grep -r "your-api-key\|template-id\|template_id" --include="*.cs" . # Find NuGet package references grep -r "CraftMyPdf\|RestSharp" --include="*.csproj" . # Find all CraftMyPDF usages in your codebase grep -r "CraftMyPdf\|craftmypdf\|api.craftmypdf.com" --include="*.cs" . grep -r "X-API-KEY" --include="*.cs" . # Find API key references grep -r "your-api-key\|template-id\|template_id" --include="*.cs" . # Find NuGet package references grep -r "CraftMyPdf\|RestSharp" --include="*.csproj" . SHELL 需要預見的重大變化 改變 CraftMyPDF IronPDF 影響 建築學 雲端 REST API 本機 .NET 函式庫 移除 HTTP 呼叫 範本 專有編輯器 標準 HTML 將模板轉換為 HTML API金鑰 每次通話都需要 新創公司取得許可證 移除 API 金鑰處理 非同步模式 必需(HTTP) 選修的 如果願意,請移除 await 函數。 錯誤處理 HTTP 狀態碼 例外情況 更改 try/catch 模式 資料綁定 JSON 模板 字串插值 簡化資料綁定 逐步遷移過程 步驟 1:更新 NuGet 套件 移除HTTP客戶端庫並安裝IronPDF: # Remove RestSharp HTTP client dotnet remove package RestSharp # Install IronPDF dotnet add package IronPdf # Remove RestSharp HTTP client dotnet remove package RestSharp # Install IronPDF dotnet add package IronPdf SHELL 步驟 2:更新命名空間引用 將 HTTP 用戶端命名空間替換為 IronPDF: // Remove these using RestSharp; using System.IO; // Add this using IronPdf; // Remove these using RestSharp; using System.IO; // Add this using IronPdf; $vbLabelText $csharpLabel 步驟 3:設定許可證(啟動時一次) 將每個請求的 API 金鑰標頭替換為單一許可證配置: // Add at application startup (Program.cs or Global.asax) // This replaces all X-API-KEY headers IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; // Add at application startup (Program.cs or Global.asax) // This replaces all X-API-KEY headers IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; $vbLabelText $csharpLabel 完整的 API 遷移參考 API 端點映射 CraftMyPDF IronPDF 筆記 POST /v1/create renderer.RenderHtmlAsPdf(html) 無需呼叫 API X-API-KEY標頭 License.LicenseKey = "..." 啟動時設定一次 template_id 標準 HTML 字串 使用任何 HTML {%name%}佔位符 $"{name}" C# 內插 標準 .NET POST /v1/merge PdfDocument.Merge(pdfs) 本地即時 POST /v1/add-watermark pdf.ApplyWatermark(html) 基於HTML Webhook回調 不需要 結果同步 限速 不適用 無限制 配置映射 CraftMyPDF 選項 IronPDF當量 筆記 template_id HTML字串 使用您自己的 HTML data JSON C# 插值 $"Hello {name}" page_size: "A4" PaperSize = PdfPaperSize.A4 orientation: "landscape" PaperOrientation = Landscape margin_top: 20 MarginTop = 20 單位:毫米 header HtmlHeader 完全支援 HTML footer HtmlFooter 完全支援 HTML 程式碼遷移範例 HTML 轉 PDF 最常見的操作體現了從雲端 API 到本地渲染的根本架構轉變。 CraftMyPDF 實作: // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { html = "<h1>Hello World</h1><p>This is a PDF from HTML</p>" } }); var response = client.Execute(request); File.WriteAllBytes("output.pdf", response.RawBytes); } } // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { html = "<h1>Hello World</h1><p>This is a PDF from HTML</p>" } }); var response = client.Execute(request); File.WriteAllBytes("output.pdf", response.RawBytes); } } $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using System; using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>"); pdf.SaveAs("output.pdf"); } } // NuGet: Install-Package IronPdf using System; using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>"); pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel IronPDF 省去了 RestClient 設定、API 金鑰標頭、範本 ID 和 HTTP 回應處理,將 15 行雲操作簡化為 4 行本機程式碼。 更多選項,請參閱HTML 轉 PDF 文件。 URL 轉 PDF CraftMyPDF 實作: // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { url = "https://example.com" }, export_type = "pdf" }); var response = client.Execute(request); File.WriteAllBytes("webpage.pdf", response.RawBytes); } } // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { url = "https://example.com" }, export_type = "pdf" }); var response = client.Execute(request); File.WriteAllBytes("webpage.pdf", response.RawBytes); } } $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using System; using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://example.com"); pdf.SaveAs("webpage.pdf"); } } // NuGet: Install-Package IronPdf using System; using IronPdf; class Program { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://example.com"); pdf.SaveAs("webpage.pdf"); } } $vbLabelText $csharpLabel IronPDF 的RenderUrlAsPdf方法可以捕捉完整的網頁,包括 JavaScript 渲染的內容。 更多選項請參閱PDF 文件的 URL 。 頁首和頁尾 CraftMyPDF 實作: // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { html = "<h1>Document Content</h1>", header = "<div>Page Header</div>", footer = "<div>Page {page} of {total_pages}</div>" } }); var response = client.Execute(request); File.WriteAllBytes("document.pdf", response.RawBytes); } } // NuGet: Install-Package RestSharp using System; using RestSharp; using System.IO; class Program { static void Main() { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); request.AddJsonBody(new { template_id = "your-template-id", data = new { html = "<h1>Document Content</h1>", header = "<div>Page Header</div>", footer = "<div>Page {page} of {total_pages}</div>" } }); var response = client.Execute(request); File.WriteAllBytes("document.pdf", response.RawBytes); } } $vbLabelText $csharpLabel IronPDF實現: // NuGet: Install-Package IronPdf using System; using IronPdf; using IronPdf.Rendering; class Program { static void Main() { var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.TextHeader = new TextHeaderFooter() { CenterText = "Page Header" }; renderer.RenderingOptions.TextFooter = new TextHeaderFooter() { CenterText = "Page {page} of {total-pages}" }; var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>"); pdf.SaveAs("document.pdf"); } } // NuGet: Install-Package IronPdf using System; using IronPdf; using IronPdf.Rendering; class Program { static void Main() { var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.TextHeader = new TextHeaderFooter() { CenterText = "Page Header" }; renderer.RenderingOptions.TextFooter = new TextHeaderFooter() { CenterText = "Page {page} of {total-pages}" }; var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>"); pdf.SaveAs("document.pdf"); } } $vbLabelText $csharpLabel IronPDF 支援使用{page}和{total-pages}等佔位符號標記進行動態頁碼編號。 更多選項請參閱頁首和頁尾文件。 模板變數轉換 CraftMyPDF 使用專有的範本佔位符,必須將其轉換為 C# 字串插值: CraftMyPDF 圖案: // CraftMyPDF template variables request.AddJsonBody(new { template_id = "invoice-template", data = new { customer = "John Doe", amount = "$1,000", items = invoiceItems } }); // CraftMyPDF template variables request.AddJsonBody(new { template_id = "invoice-template", data = new { customer = "John Doe", amount = "$1,000", items = invoiceItems } }); $vbLabelText $csharpLabel IronPDF 圖案: // C# string interpolation var html = $@" <html> <body> <h1>Invoice</h1> <p>Customer: {customerName}</p> <p>Amount: {amount}</p> {GenerateItemsTable(invoiceItems)} </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(html); // C# string interpolation var html = $@" <html> <body> <h1>Invoice</h1> <p>Customer: {customerName}</p> <p>Amount: {amount}</p> {GenerateItemsTable(invoiceItems)} </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(html); $vbLabelText $csharpLabel 關鍵遷移說明 移除所有 HTTP 程式碼 最顯著的變化是消除了對網路的依賴。 IronPDF 運行在本地端——無需 RestClient,無需 API 調用,無需回應處理: // CraftMyPDF - HTTP required var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); var response = await client.ExecuteAsync(request); // IronPDF - no HTTP var pdf = renderer.RenderHtmlAsPdf(html); // CraftMyPDF - HTTP required var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", "your-api-key"); var response = await client.ExecuteAsync(request); // IronPDF - no HTTP var pdf = renderer.RenderHtmlAsPdf(html); $vbLabelText $csharpLabel 移除速率限制代碼 CraftMyPDF 會限制 API 呼叫頻率,並要求啟用重試機制。 IronPDF 沒有限制: // CraftMyPDF - needed to avoid 429 errors await Task.Delay(100); if (response.StatusCode == TooManyRequests) { /* retry */ } // IronPDF - no limits, just generate var pdf = renderer.RenderHtmlAsPdf(html); // Remove all rate limit code! // CraftMyPDF - needed to avoid 429 errors await Task.Delay(100); if (response.StatusCode == TooManyRequests) { /* retry */ } // IronPDF - no limits, just generate var pdf = renderer.RenderHtmlAsPdf(html); // Remove all rate limit code! $vbLabelText $csharpLabel 移除 Webhook 處理程序 CraftMyPDF 使用非同步 webhook 實現 PDF 自動完成。 IronPDF是同步的-PDF檔案立即即可產生: // CraftMyPDF - webhook callback required // POST with webhook_url, wait for callback // IronPDF - PDF ready immediately var pdf = renderer.RenderHtmlAsPdf(html); pdf.SaveAs("output.pdf"); // No callback needed! // CraftMyPDF - webhook callback required // POST with webhook_url, wait for callback // IronPDF - PDF ready immediately var pdf = renderer.RenderHtmlAsPdf(html); pdf.SaveAs("output.pdf"); // No callback needed! $vbLabelText $csharpLabel 預設同步 如果僅在 HTTP 呼叫中需要使用 async/await 模式,則應將其移除: // CraftMyPDF - async required var response = await client.ExecuteAsync(request); // IronPDF - sync by default (async available if needed) var pdf = renderer.RenderHtmlAsPdf(html); // CraftMyPDF - async required var response = await client.ExecuteAsync(request); // IronPDF - sync by default (async available if needed) var pdf = renderer.RenderHtmlAsPdf(html); $vbLabelText $csharpLabel 遷移後檢查清單 程式碼遷移完成後,請驗證以下內容: 執行所有 PDF 生成測試 比較輸出品質(IronPDF 的 Chromium 引擎可實現像素級完美渲染) 衡量效能提升(毫秒與秒) 驗證所有範本是否已正確轉換 測試無速率限制的批量處理 在所有目標環境中進行測試 更新 CI/CD 管線 取消 CraftMyPDF 訂閱 從 secrets/config 移除 API 金鑰 讓您的 PDF 基礎架構面向未來 隨著 .NET 10 即將發布,C# 14 也引入了新的語言特性,選擇本地 PDF 庫可以消除雲端 API 棄用風險和版本相容性問題。 IronPDF 的永久許可模式意味著,隨著專案延續到 2025 年和 2026 年,您的遷移投資將無限期地獲得回報——無需支付持續的訂閱費用,資料也不會離開您的基礎設施。 其他資源 IronPDF 文件 HTML 轉 PDF 教學課程 API 參考 NuGet 套件 -授權選項 從 CraftMyPDF 遷移到 IronPDF 可以消除對雲端的依賴、網路延遲、單一 PDF 的成本以及模板鎖定,同時提供可離線運行的像素級 Chromium 渲染效果。從 REST 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 DinkToPdf to IronPDF in C#How to Migrate from ComPDFKit to Ir...
發表日期 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. 閱讀更多