使用IRONPDF PDF轉換器.NET(開發者教程) Curtis Chau 更新:2025年6月22日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 1.0 引言 Adobe 的可攜式文件格式 (PDF) 被廣泛用於文件檢視和交換。 開發人員經常需要創建 PDF 文件以滿足客戶需求,而現代庫簡化了這一過程。 為專案選擇庫時,需要考慮建置、讀取和轉換功能等特性。 2.0 IronPDF功能 IronPDF是一個功能強大的庫,用於建立、讀取和編輯 PDF 文檔,並能夠使用 Chrome 引擎將 HTML 轉換為 PDF。它支援多種 Web 元件,可用於ASP.NET Web 應用程式和傳統的 Windows 應用程式。 該程式庫允許使用 HTML5、 JavaScript、CSS 和圖像創建視覺上吸引人的 PDF,並包含一個強大的 HTML 到 PDF 轉換器。 IronPDF庫支援多種 PDF 生成輸入,包括圖像檔案轉 PDF 、 HTML5 轉 PDF 、 ASPX 轉 PDF以及Razor/MVC 視圖轉換。 該庫具有創建互動式 PDF 文件、編輯和發送互動式表單、分割 PDF 文件、提取文字和圖像、文字搜尋以及將 PDF 頁面柵格化為圖像的工具。 本程式庫允許使用 URL 作為 PDF 文件的基礎,並支援使用者代理程式、代理伺服器、cookie、HTTP 標頭和表單變量,以便在 HTML 登入表單後面進行身份驗證。 IronPDF允許使用者透過提供使用者名稱和密碼來存取受密碼保護的 PDF 檔案。 該程式庫支援讀取和編輯現有的 PDF 文件。 使用者可以使用IronPDF為 PDF 文件添加文字、圖形、整理書籤、水印、自訂頁首和頁腳,以及從 PDF 文件中提取圖像。 IronPDF允許在新文件或現有文件中分割和合併頁面,並且可以從文字產生 PDF 對象,而無需 Adobe Acrobat Reader。 支援 CSS 媒體檔案和CSS 檔案到 PDF 的轉換。 使用者可以使用IronPDF新增新的可填寫 PDF 表單或完成現有的表單。 IronPDF也可以將 PDF 頁面轉換為各種影像格式,例如 JPEG、PNG 等。 3.0 從 URL 建立 PDF 文檔 使用 IronPDF 內建的 Chrome 瀏覽器和 API 庫,從網頁產生 PDF 檔案非常容易。 只需提供 URL,即可使用IronPDF API 庫將其轉換為 PDF 文件。 只需幾行程式碼即可快速完成文件轉換: // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified URL to a PDF var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified URL to a PDF var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); $vbLabelText $csharpLabel 可使用RenderUrlAsPdf方法快速將 URL 轉換為 PDF 文件。 只需提供 URL 和所需的儲存位置, IronPDF就會根據以上資訊產生 PDF 檔案。 這樣只需幾行程式碼即可輕鬆將網頁轉換為 PDF 文件。 從 Google URL 產生的 PDF 文件 4.0 從 HTML 字串建立 PDF 使用IronPDF API 庫可以快速將 HTML 字串轉換為 PDF 檔案。 以下程式碼片段可以將 HTML 字串轉換為文檔,並且可以將任何 HTML 標籤轉換為 PDF 文件。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified HTML string to a PDF var pdf = renderer.RenderHtmlAsPdf("<p>Hello world!!</p>"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified HTML string to a PDF var pdf = renderer.RenderHtmlAsPdf("<p>Hello world!!</p>"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); $vbLabelText $csharpLabel 此程式碼片段示範如何使用 RenderHtmlAsPdf 函數將 HTML 文字轉換為 PDF。 將 HTML 轉換為字串的函數可以接受所需的任意長度的 HTML 程式碼。 然後,可以使用SaveAs功能儲存文檔,從而快速輕鬆地完成該過程。 從 HTML 字串輸出 PDF 文件 5.0 從 HTML 文件建立 PDF 文件 IronPDF API 庫可以快速將 HTML 檔案轉換為 PDF 檔案。 使用下列範例程式碼,任何 HTML 標籤都可以轉換為 PDF 檔案。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified HTML file to a PDF var pdf = renderer.RenderHtmlFileAsPdf("test.html"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified HTML file to a PDF var pdf = renderer.RenderHtmlFileAsPdf("test.html"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); $vbLabelText $csharpLabel HTML程式碼如下: <p style="color:red">Hello world</p> <p style="color:red">Hello world</p> HTML 從 HTML 文件輸出的 PDF 文件 6.0 從富文本文件建立 PDF 文件 IronPDF API 庫還允許從富文本檔案 (RTF) 快速建立 PDF。 以下範例程式碼可用於將任意數量的 RTF 檔案轉換為單一 PDF 檔案。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified RTF file to a PDF var pdf = renderer.RenderRtfFileAsPdf("test.rtf"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified RTF file to a PDF var pdf = renderer.RenderRtfFileAsPdf("test.rtf"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); $vbLabelText $csharpLabel 從 RTF 文件輸出 PDF 文件 上圖中,左側顯示的是來源文檔,右側顯示的是轉換後的 PDF 文件。 此外,我們可以使用下面提供的程式碼,利用 RTF 字串建立 PDF。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified RTF string to a PDF var pdf = renderer.RenderRtfStringAsPdf("{\\rtf1...}"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified RTF string to a PDF var pdf = renderer.RenderRtfStringAsPdf("{\\rtf1...}"); // Save the PDF to the specified path pdf.SaveAs("result.pdf"); $vbLabelText $csharpLabel 7.0 從 Markdown 文件建立 PDF 文件 透過IronPDF API 模組,可以從 Markdown 文件快速產生 PDF 文件。 使用下面所示的轉換範例程式碼,可以將任意數量的 Markdown 文件轉換為 PDF 文件。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified Markdown file to a PDF var pdf = renderer.RenderMarkdownFileAsPdf("Markdown.md"); // Save the PDF to the specified path pdf.SaveAs("Markdown_result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified Markdown file to a PDF var pdf = renderer.RenderMarkdownFileAsPdf("Markdown.md"); // Save the PDF to the specified path pdf.SaveAs("Markdown_result.pdf"); $vbLabelText $csharpLabel 從 Markdown 文件輸出的 PDF 文件 如上圖所示,原始文件在左側,轉換後的 PDF 文件在右側。 下面提供的程式碼可以將 MD 字串轉換為 PDF。 有關使用IronPDF進行 HTML 轉換的更多信息,請訪問此HTML 轉 PDF 轉換教程。 // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified Markdown string to a PDF var pdf = renderer.RenderMarkdownStringAsPdf("# Hello world\n\nHello world"); // Save the PDF to the specified path pdf.SaveAs("Markdown_result.pdf"); // Create a new instance of the ChromePdfRenderer class var renderer = new IronPdf.ChromePdfRenderer(); // Convert the specified Markdown string to a PDF var pdf = renderer.RenderMarkdownStringAsPdf("# Hello world\n\nHello world"); // Save the PDF to the specified path pdf.SaveAs("Markdown_result.pdf"); $vbLabelText $csharpLabel 有關如何使用IronPDF API 庫的更多信息,請參閱開發者文件IronPDF文檔資源。 8.0 結論 IronPDF庫提供免費的開發許可,根據開發人員的需求,還可以購買多種許可用於生產環境。 Lite 套餐的初始價格為 $799,沒有後續費用。 這些許可證包含永久許可證、30 天退款保證、一年的產品支援和升級,以及 SaaS 和 OEM 的重新分發可能性。 這些都是一次性購買,可用於開發、建造和製作。 IronPDF還提供額外的限時免費許可證和用於防止重新分發的免費許可證。 有關IronPDF定價和許可資訊的完整概述,請訪問IronPDF許可資訊頁面。 常見問題解答 如何使用 .NET 將 HTML 轉換為 PDF 而不失去格式? 您可以使用 IronPDF 通過利用 Chrome 引擎將 HTML 轉換為 PDF 而不失去格式。該庫支持 HTML5、JavaScript 和 CSS,確保您的 PDF 保留其原始佈局和設計。 有哪些方法可用於將 URL 轉換為 PDF? IronPDF 提供 RenderUrlAsPdf 方法,允許通過使用 ChromePdfRenderer 類輕鬆地將 URL 轉換為 PDF 文檔。 是否有方法可以在 C# 中將 Markdown 轉換為 PDF? 是的,IronPDF 可以通過使用 RenderMarkdownFileAsPdf 方法將 Markdown 文件轉換為 PDF。這使開發者能夠高效地將 Markdown 內容轉換為 PDF 格式。 如何使用 .NET 將 RTF 文件轉換成 PDF 文檔? IronPDF 可以使用 RenderRtfFileAsPdf 方法將 RTF 文件轉換為 PDF,允許快速準確地將富文本文件轉換為 PDF 格式。 我可以從 PDF 文件中提取文本和圖像嗎? 是的,IronPDF 允許您輕鬆地從 PDF 文檔中提取文本和圖像,提供搜索和操作 PDF 中的文本和圖像的功能。 有哪些選項可供創建交互式 PDF 表單? IronPDF 支持創建和編輯交互式 PDF 表單,允許開發者為 PDF 文檔添加表單字段、圖形、書籤和水印。 如何在 .NET 中合併或拆分 PDF 文檔? IronPDF 提供合併和拆分 PDF 文檔的功能,允許開發者將多個 PDF 合併為一個或將一個 PDF 分割為多個文檔。 IronPDF 在生產環境中提供哪些許可選項? IronPDF 提供多種生產環境的許可選項,包括不需持續成本的基本套裝。許可提供永久使用權、30 天退款保證,以及一年的產品更新和支持。 IronPDF 可以在 ASP.NET 網路和 Windows 應用程序中使用嗎? 是的,IronPDF 與 ASP.NET 網路應用程序和傳統 Windows 應用程序兼容,為開發者在不同環境中提供了彈性。 IronPDF 支持密碼保護的 PDF 文件嗎? IronPDF 可以處理密碼保護的 PDF 文件,允許用戶提供所需的憑證來讀取和編輯這些文檔。 .NET 10:IronPDF是否完全支持針對.NET 10的專案? 是的。IronPDF完全相容於.NET 10——囊括新的執行環境和C#語言增強功能——涵蓋桌面、網頁、微服務和雲端/容器環境。在.NET 10專案中開箱即用,無需變通方案或自訂API。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新2026年3月1日 如何在.NET中使用IronPDF創建PDF檔案(C#教程) 發現用於創建C# PDF文件的有效方法,提升您的編碼技能並簡化您的項目。立即閱讀文章! 閱讀更多 更新2026年2月27日 如何在C#中合併PDF文件 使用 IronPDF 合併 PDF 文件。學習如何使用簡單的 VB.NET 程式碼將多個 PDF 文件合併成一個文檔。包含逐步範例。 閱讀更多 更新2026年3月1日 C# PDFWriter教程,適用於.NET 10開發者 通過這個面向開發人員的逐步指南,學習如何使用C# PDFWriter高效創建PDF。閱讀本文以提高您的技能! 閱讀更多 ASP PDF查看器(開發者教程)如何在C#中裁剪PDF文件