MIGRATION GUIDES How to Migrate from PDFmyURL to IronPDF in C# Curtis Chau 發表日期:2026年2月1日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 PDFmyURL 是一款基於雲端的 API 服務,旨在將 URL 和 HTML 內容轉換為 PDF 文件。 該服務在外部伺服器上處理所有轉換,提供了一條簡單的整合路徑,所需的本地基礎設施極少。 然而,這種依賴雲端的架構為處理敏感資料、需要離線功能或需要避免持續訂閱費用的生產應用程式帶來了重大問題。 本指南提供了從 PDFmyURL 到 IronPDF 的完整遷移路徑,包括逐步說明、程式碼比較和實用範例,供正在評估此過渡的專業 .NET 開發人員參考。 為什麼要從 PDFmyURL 遷移? PDFmyURL的雲端處理模式帶來了一些開發團隊必須考慮的挑戰: 隱私和資料安全:您轉換的每個文件都會傳輸到 PDFmyURL 的伺服器並經過其伺服器——敏感合約、財務報告和個人資料都在外部進行處理。 持續訂閱費用:每月起價 39 美元,年費用超過 468 美元,且不擁有產品所有權。這種訂閱模式意味著無論使用情況如何,都需要持續付費。 網路依賴性:每次轉換都需要網路連線。 應用程式無法在離線狀態或網路中斷期間處理 PDF 檔案。 速率限制和節流:在高峰使用期間,API 呼叫可能會受到節流,這可能會影響應用程式的效能。 服務可用性:您的應用程式依賴第三方服務在線上且功能正常。 供應商鎖定: API 變更可能會在未事先通知的情況下破壞您的集成,需要被動地更新程式碼。 IronPDF 與 PDFmyURL:功能對比 了解架構差異有助於技術決策者評估遷移投資: 方面 PDFmyURL IronPDF 處理地點 外部伺服器 本地(您的伺服器) 類型 API 封裝器 .NET 函式庫 驗證 每個請求的 API 金鑰 一次許可證密鑰 需要網路 每次轉換 僅初始設定 定價模式 每月訂閱費(39美元起) 提供永久許可 速率限制 是的(取決於具體方案) 沒有任何 資料隱私 向外部發送的數據 資料保留在本地 HTML/CSS/JS 支持 符合 W3C 標準 全鉻發動機 非同步模式 必需(僅限非同步) 同步和非同步選項 PDF 處理 有限的 全套功能(合併、分割、編輯) 用例 小批量應用 高容量和企業 快速入門:PDFmyURL 到 IronPDF 的遷移 透過這些基礎步驟,遷移工作可以立即開始。 步驟 1:替換 NuGet 套件 移除 PDFmyURL 軟體包: # Remove PDFmyURL packages dotnet remove package PdfMyUrl dotnet remove package Pdfcrowd # Remove PDFmyURL packages dotnet remove package PdfMyUrl dotnet remove package Pdfcrowd SHELL 安裝 IronPDF: # Install IronPDF dotnet add package IronPdf # Install IronPDF dotnet add package IronPdf SHELL 步驟 2:更新命名空間 將 PDFmyURL 命名空間替換為 IronPdf: // Before: PDFmyURL using PdfMyUrl; using Pdfcrowd; // After: IronPDF using IronPdf; using IronPdf.Rendering; // Before: PDFmyURL using PdfMyUrl; using Pdfcrowd; // After: IronPDF using IronPdf; using IronPdf.Rendering; $vbLabelText $csharpLabel 步驟 3:初始化許可證 在應用程式啟動時新增許可證初始化: IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; $vbLabelText $csharpLabel 程式碼遷移範例 將 URL 轉換為 PDF URL 轉 PDF 操作展示了 PDFmyURL 和 IronPDF 之間 API 的根本差異。 PDFmyURL 方法: // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); client.convertUrlToFile("https://example.com", "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); client.convertUrlToFile("https://example.com", "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } $vbLabelText $csharpLabel IronPDF 方法: // NuGet: Install-Package IronPdf using IronPdf; using System; class Example { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://example.com"); pdf.SaveAs("output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using System; class Example { static void Main() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://example.com"); pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel PDFmyURL 要求為每個轉換請求建立一個具有使用者名稱和 API 金鑰憑證的HtmlToPdfClient ,然後使用 URL 和輸出路徑呼叫convertUrlToFile() 。 整個操作必須用 try-catch 語句包裹起來,以處理 PDFmyURL 的自訂Error類型。 IronPDF 將此簡化為三行程式碼:建立一個ChromePdfRenderer ,呼叫RenderUrlAsPdf() ,然後使用內建的SaveAs()方法。 無需每次請求都提供憑證——許可證在應用程式啟動時設定一次。 有關更高級的 URL 轉到 PDF 場景,請參閱URL 轉 PDF 文件。 將 HTML 字串轉換為 PDF HTML字串轉換清晰地顯示了模式差異。 PDFmyURL 方法: // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); string html = "<html><body><h1>Hello World</h1></body></html>"; client.convertStringToFile(html, "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); string html = "<html><body><h1>Hello World</h1></body></html>"; client.convertStringToFile(html, "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } $vbLabelText $csharpLabel IronPDF 方法: // NuGet: Install-Package IronPdf using IronPdf; using System; class Example { 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; using System; class Example { 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 PDFmyURL 使用convertStringToFile()函數將 HTML 內容傳送到外部伺服器進行處理。 IronPDF 的RenderHtmlAsPdf()使用 Chromium 渲染引擎在本機處理所有內容。 請參閱HTML 轉 PDF 轉換指南,以了解更多選項。 HTML 文件轉換及頁面設定 每個圖書館對紙張尺寸、方向和邊距的配置都需要不同的方法。 PDFmyURL 方法: // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); client.setPageSize("A4"); client.setOrientation("landscape"); client.setMarginTop("10mm"); client.convertFileToFile("input.html", "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } // Install PDFmyURL SDK using System; using Pdfcrowd; class Example { static void Main() { try { var client = new HtmlToPdfClient("username", "apikey"); client.setPageSize("A4"); client.setOrientation("landscape"); client.setMarginTop("10mm"); client.convertFileToFile("input.html", "output.pdf"); } catch(Error why) { Console.WriteLine("Error: " + why); } } } $vbLabelText $csharpLabel IronPDF 方法: // NuGet: Install-Package IronPdf using IronPdf; using IronPdf.Rendering; using System; class Example { static void Main() { var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; renderer.RenderingOptions.MarginTop = 10; var pdf = renderer.RenderHtmlFileAsPdf("input.html"); pdf.SaveAs("output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using IronPdf.Rendering; using System; class Example { static void Main() { var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; renderer.RenderingOptions.MarginTop = 10; var pdf = renderer.RenderHtmlFileAsPdf("input.html"); pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel PDFmyURL 使用帶有字串參數的 setter 方法,例如setPageSize("A4")和setMarginTop("10mm") 。 IronPDF 透過RenderingOptions提供強類型屬性,枚舉類型如PdfPaperSize.A4 ,整數值表示以毫米為單位的邊距。 PDFmyURL API 到 IronPDF 映射參考 此映射透過顯示直接的 API 等效項來加速遷移: 核心課程 PDFmyURL IronPDF 筆記 HtmlToPdfClient ChromePdfRenderer 主轉換類 PdfMyUrlClient ChromePdfRenderer 替代客戶類別 API 回應對象 PdfDocument 結果 PDF 對象 方法 PDFmyURL IronPDF 筆記 client.convertUrlToFile(url, file) renderer.RenderUrlAsPdf(url).SaveAs(file) PDF檔案的URL client.convertStringToFile(html, file) renderer.RenderHtmlAsPdf(html).SaveAs(file) 將 HTML 字串轉換為 PDF client.convertFileToFile(input, output) renderer.RenderHtmlFileAsPdf(input).SaveAs(output) 文件歸檔 response.GetBytes() pdf.BinaryData 取得原始位元組 response.GetStream() pdf.Stream 獲取串流 配置選項 PDFmyURL(setXxx 方法) IronPDF(渲染選項) 筆記 setPageSize("A4") .PaperSize = PdfPaperSize.A4 紙張尺寸 setPageSize("Letter") .PaperSize = PdfPaperSize.Letter 美國信紙 setOrientation("landscape") .PaperOrientation = PdfPaperOrientation.Landscape 方向 setOrientation("portrait") .PaperOrientation = PdfPaperOrientation.Portrait 肖像 setMarginTop("10mm") .MarginTop = 10 上邊距(毫米) setMarginBottom("10mm") .MarginBottom = 10 下邊距(毫米) setMarginLeft("10mm") .MarginLeft = 10 左邊距(毫米) setMarginRight("10mm") .MarginRight = 10 右邊距(毫米) setHeaderHtml(html) .HtmlHeader = new HtmlHeaderFooter { HtmlFragment = html } 標題 setFooterHtml(html) .HtmlFooter = new HtmlHeaderFooter { HtmlFragment = html } 頁尾 setJavascriptDelay(500) .RenderDelay = 500 JS 等待時間(毫秒) setDisableJavascript(true) .EnableJavaScript = false 禁用 JavaScript setUsePrintMedia(true) .CssMediaType = PdfCssMediaType.Print 列印 CSS 身份驗證比較 PDFmyURL IronPDF new HtmlToPdfClient("username", "apikey") IronPdf.License.LicenseKey = "LICENSE-KEY" 每個請求的 API 金鑰 創業初期的一次 每次通話都需要 全域設定一次 常見遷移問題及解決方案 問題 1:API 金鑰與許可證金鑰 PDFmyURL:每次轉換請求都需要憑證。 解決方案:在應用程式啟動時設定一次 IronPDF 許可證: // PDFmyURL: API key per request var client = new HtmlToPdfClient("username", "apikey"); // IronPDF: One-time license at startup IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; // Set once, typically in Program.cs or Startup.cs // PDFmyURL: API key per request var client = new HtmlToPdfClient("username", "apikey"); // IronPDF: One-time license at startup IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"; // Set once, typically in Program.cs or Startup.cs $vbLabelText $csharpLabel 問題 2:頁首/頁尾中的佔位符語法 PDFmyURL:使用{page_number}和{total_pages}佔位符。 解決方案:更新為 IronPDF 的佔位格式: // PDFmyURL: "Page {page_number} of {total_pages}" // IronPDF: "Page {page} of {total-pages}" // PDFmyURL: "Page {page_number} of {total_pages}" // IronPDF: "Page {page} of {total-pages}" $vbLabelText $csharpLabel 問題 3:非同步模式 PDFmyURL:需要 async/await 模式。 解決方案: IronPDF 預設是同步的; 如果需要,請將其包裝以支援非同步操作: // PDFmyURL: Native async var response = await client.ConvertUrlAsync(url); // IronPDF: Sync by default, wrap for async var pdf = await Task.Run(() => renderer.RenderUrlAsPdf(url)); // PDFmyURL: Native async var response = await client.ConvertUrlAsync(url); // IronPDF: Sync by default, wrap for async var pdf = await Task.Run(() => renderer.RenderUrlAsPdf(url)); $vbLabelText $csharpLabel 問題 4:錯誤處理 PDFmyURL:使用自訂的Pdfcrowd.Error異常類型。 解決方案:更新 IronPDF 異常的 catch 程式碼區塊: // PDFmyURL: Pdfcrowd.Error catch (Pdfcrowd.Error e) { ... } // IronPDF: Standard exceptions catch (IronPdf.Exceptions.IronPdfRenderingException e) { ... } // PDFmyURL: Pdfcrowd.Error catch (Pdfcrowd.Error e) { ... } // IronPDF: Standard exceptions catch (IronPdf.Exceptions.IronPdfRenderingException e) { ... } $vbLabelText $csharpLabel 問題 5:配置模式 PDFmyURL:使用帶有字串值的 setter 方法。 解決方案:使用強類型的 RenderingOptions 屬性: // PDFmyURL: Setter methods client.setPageSize("A4"); client.setOrientation("landscape"); // IronPDF: Properties with enums renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; // PDFmyURL: Setter methods client.setPageSize("A4"); client.setOrientation("landscape"); // IronPDF: Properties with enums renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; $vbLabelText $csharpLabel PDFmyURL遷移檢查清單 遷移前任務 審核您的程式碼庫,找出所有 PDFmyURL 的使用情況: # Find PDFmyURL usage grep -r "PdfMyUrl\|Pdfcrowd\|HtmlToPdfClient" --include="*.cs" . # Find API key references grep -r "apikey\|api-key\|api_key" --include="*.cs" --include="*.json" --include="*.config" . # Find placeholder patterns to migrate grep -r "{page_number}\|{total_pages}" --include="*.cs" . # Find PDFmyURL usage grep -r "PdfMyUrl\|Pdfcrowd\|HtmlToPdfClient" --include="*.cs" . # Find API key references grep -r "apikey\|api-key\|api_key" --include="*.cs" --include="*.json" --include="*.config" . # Find placeholder patterns to migrate grep -r "{page_number}\|{total_pages}" --include="*.cs" . SHELL 記錄目前使用的配置選項。 使用環境變數儲存許可證密鑰方案。 程式碼更新任務 刪除 PDFmyURL/Pdfcrowd NuGet 套件 安裝 IronPdf NuGet 套件 更新所有命名空間導入 將 API 金鑰驗證替換為 IronPDF 許可證金鑰 將 setter 方法轉換為 RenderingOptions 屬性 更新頁首/頁尾中的佔位符語法( {page_number} → {page} , {total_pages} → {total-pages} ) 更新 IronPDF 異常類型的錯誤處理程式碼 新增 IronPDF 許可證啟動初始化功能 遷移後測試 遷移完成後,請確認以下幾個面向: 測試 PDF 輸出品質符合預期 驗證非同步模式是否正常運作 將渲染保真度與先前的輸出進行比較 測試所有模板變體是否都能正確渲染 驗證頁面設定(大小、方向、邊距) 如果部署到 Linux 伺服器,請安裝 Linux 依賴項 遷移到 IronPDF 的主要優勢 從 PDFmyURL 遷移到 IronPDF 可帶來以下幾個關鍵優勢: 完全隱私:文件絕對不會離開您的伺服器。 所有處理都在本地進行,消除了敏感內容的資料安全隱患。 一次性費用:永久授權選項免除定期訂閱費用。 無論使用量多少,都不再需要每月支付費用。 離線功能:完成初始設定後,無需網路連線即可運作。網路中斷不會影響 PDF 產生。 無速率限制:處理無限量文檔,無需擔心限速問題。 更低的延遲:沒有網路開銷意味著更快的轉換速度,尤其適用於高容量應用。 完全控制:您控制處理環境,而不是第三方服務。 現代 Chromium 引擎:完全支援 CSS3 和 JavaScript,採用與 Chrome 瀏覽器相同的渲染引擎。 積極開發:隨著 .NET 10 和 C# 14 的普及,IronPDF 將持續更新,確保與目前和未來的 .NET 版本相容。 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 TallComponents to IronPDF in C#How to Migrate from Syncfusion PDF ...
發表日期 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. 閱讀更多