產品比較 CraftMyPDF與IronPDF之間的比較 Curtis Chau 更新日期:7月 28, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article PDF,即可攜式文檔格式,是由Adobe開發的一種文件格式,便於文件交換。 它確保文件在任何設備上看起來都一樣,保持格式、字體和圖像不變。 PDF文件安全、互動且緊湊,使其在分享時保持內容完整。 C# PDF庫對於處理PDF的開發人員至關重要。 這些工具有助於從PDF中創建、修改和提取內容。 它們支持表單處理、數位簽名等功能,並可跨不同平台工作,提高了PDF處理的效率。 使用C# PDF庫,開發人員可以將PDF功能添加到應用程序中,使文檔創建、編輯和管理更容易實現程式化。 In this article, we will compare two different approaches to working with PDFs: the IronPDF C# library and the Craftmypdf API. 我們將查看其功能,提供代碼示例,並討論其許可證。 1. CraftMyPDF API 基礎解決方案 CraftMyPDF 是一款多功能API,設計用於創建PDF文檔。 它提供一個基於Web的拖放編輯器,允許您直接在瀏覽器中設計PDF模板。 此功能特別適用於從可重用模板和JSON數據創建像素級精確的PDF。 編輯器包括豐富的布局組件集,支持強大的表達式、高級格式化和數據綁定,使其成為各種PDF生成需求的強大工具。 1.1 CraftMyPDF的關鍵功能 拖放編輯器: CraftMyPDF的直觀拖放編輯器簡化了PDF模板的創建。 您可以在無需任何代碼知識的情況下設計模板,讓所有技能水平的用戶都能使用。 此編輯器允許您添加各種元素,如文本、圖像和形狀,自定義其布局和外觀。 模板重用性:該平台支持可重用的模板,這可以節省大量時間。 一旦設計好模板後,它可以與不同的數據集一起反覆使用,非常適合生成發票、報告和證書等文件。 您可以使用PDF模板編輯器對其進行編輯。 JSON數據集成: CraftMyPDF允許與JSON數據無縫集成。 這意味著您可以將動態數據導入您的模板以生成自定義PDF文檔。 此功能特別適用於需要生成具有可變內容文檔的應用程序,例如個性化發票或詳細報告。 高級格式化和表達式:API支持高級格式化選項和表達式,使您能夠創建複雜的文檔。 您可以按照您的規格格式化日期、數字和貨幣,並使用表達式根據您的數據動態生成內容。 API集成: CraftMyPDF可以使用其REST API集成到各種平台中。 它支持與無代碼平台如Zapier和Make.com的集成,以及自定義應用程序。 這種靈活性允許開發人員將PDF生成功能集成到工作流程中,並自動化文檔創建過程。 可填寫的組件: 平台還支持可填寫的PDF組件,如文本字段、複選框和下拉框。 此功能對於創建用戶可以電子填寫的互動表單至關重要。 安全和合規: CraftMyPDF確保安全訪問已生成的PDF,並支持符合GDPR等數據保護法規的區域API端點。 注重安全性使其在處理敏感文檔時成為可靠的選擇。 2. IronPDF 介紹 IronPDF PDF Library for .NET Developers 是一款為.NET開發人員設計的強大而多功能的PDF庫,提供生成、編輯和管理PDF文檔的廣泛功能。 IronPDF使用C#編寫,通過允許開發人員從HTML,CSS,JavaScript和圖像格式生成像素級精確的PDF文檔,簡化了PDF的處理過程。 其與.NET的集成使其成為任何需要PDF功能的應用程序的強大工具,從簡單的文件生成到複雜的文檔操作。 2.1 IronPDF的關鍵功能 HTML到PDF轉換: IronPDF在將HTML,CSS和JavaScript直接轉換為PDF文檔方面非常出色。 這包括HTML5和CSS3的支持,確保您的Web內容在生成的PDF中看起來如預期一樣。 轉換過程保持像素級精確,適合Web到印刷應用程序。 URL到PDF:您可以從任何URL生成PDF,輕鬆將網頁保存為PDF文件。 此功能適用於存檔網頁內容或從在線數據生成報告。 圖像到PDF: IronPDF支持將各種圖像格式,包括JPG,PNG,GIF,BMP和SVG,轉換為PDF文檔。 此功能適用於創建相冊、圖像畫廊或將視覺內容集成到您的PDF中。 表單填寫和數據提取:該庫允許既創建又程式化填寫PDF表單。 此外,您可以從現有表單中提取數據,實現無縫數據處理和與其他系統的集成。 數字簽名與安全: IronPDF提供了強大的安全功能,包括可以添加數字簽名,設置密碼和定義用戶權限。 這確保您的PDF文檔安全並符合行業標準。 PDF編輯:您可以通過添加、複製或刪除頁面來編輯現有PDF文檔。 導入現有PDF文件。 IronPDF還允許合併和拆分PDF,使其成為文檔管理的綜合工具。 註釋和附件: IronPDF支持添加註釋如便簽,以及將附件嵌入PDF文檔中。 此功能對於協作文檔審查和添加補充信息是有用的。 頁眉、頁腳和水印:該庫使您能夠為PDF文檔添加自定義的頁眉、頁腳和水印。 這些元素可以從HTML生成,提供設計和內容管理上的靈活性。 跨平台兼容性: IronPDF在包括Windows、macOS、Linux、Docker、Azure和AWS等多個平台上無縫運行。 它支持.NET Core、.NET Standard和.NET Framework,確保廣泛的兼容性和在不同環境中的易於部署。 性能優化:通過完全多線程和異步支持,IronPDF為批處理和高容量PDF生成任務優化性能。 這確保了資源的高效使用和更快的文檔處理。 綜合文檔和支持: IronPDF配有詳細的文檔、教程和示例,使開發人員能夠輕鬆入手。 該庫還提供24/5技術支持,幫助用戶迅速解決問題。 無外部依賴: IronPDF作為單個DLL運行,無需額外的軟件或安裝。 這簡化了部署並減少了與其他軟件組件的潛在衝突。 IronPDF旨在提高生產力並簡化.NET應用程序中的PDF管理。 其豐富的功能集結合易用性和全面的支持,使其成為開發人員不可或缺的工具。 3. 在Visual Studio中創建C#應用程序 在Visual Studio中創建C#控制台應用程序涉及多個步驟。 以下是詳細指南,以幫助您設置和開始項目。 3.1. 打開Visual Studio 首先,確保Visual Studio已安裝在您的計算機上。 在開始菜單中搜索或單擊桌面圖標打開Visual Studio。 3.2. 創建新項目 打開Visual Studio後,按照以下步驟創建新項目: 在開始頁上單擊“創建新項目”。 在“創建新項目”窗口中,將顯示一系列項目模板。 使用搜索欄查找“控制台應用程序”或從模板列表中選擇它。 3.3. 選擇項目模板 從搜索結果或列表中選擇“控制台應用程序 (.NET Core)”或“控制台應用程序 (.NET Framework)”,根據您的偏好或項目需求進行選擇。 3.4. 配置您的項目 選擇控制台應用程序模板後,您需要配置新項目: 項目名稱:輸入您的項目的名稱。 這將是保存您的項目文件的文件夾的名稱。 位置:選擇您希望保存項目的文件夾。 解決方案名稱:通常與您的項目名稱相同,但如果您計劃在一個解決方案中包含多個項目,可以更改它。 單擊“創建”以繼續。 4. 安装IronPDF 要開始使用IronPDF,您有三種主要的安裝方法:通過使用NuGet包管理器、NuGet包管理器控制台以及從NuGet網站下載。 4.1 NuGet包管理器 首先,讓我們來談談NuGet包管理器。 如果您使用的是Visual Studio,這種方法簡單易用。 打開您的項目,右鍵點擊解決方案資源管理器中的“引用”或“依賴項”節點。 從上下文菜單中選擇“管理NuGet包”。 在NuGet包管理器中,確保選中“瀏覽”選項卡,然後在搜索框中輸入“IronPDF”。 定位到IronPDF包後,單擊“安裝”。這一操作會將IronPDF庫添加到您的項目中並配置好使用。 4.2 NuGet包管理器控制台 接下來,NuGet包管理器控制台提供另一種方便的方法來安裝IronPDF。 欲訪問此功能,請在Visual Studio的“工具”菜單中,選擇“NuGet包管理器”,然後選擇“包管理器控制台”。在控制台窗口輸入以下命令: Install-Package IronPdf 然後按回車鍵。 此命令將IronPDF包直接下載並安裝到您的項目中。 對於那些喜歡在Visual Studio環境內使用命令行工具的用戶來說,這種方法十分高效。 4.3 NuGet網站 最後,您可以直接從NuGet網站下載IronPDF包。 如果您需要手動管理包版本或在不允許直接包管理的環境中工作,這種方法特別有用。 前往NuGet網站搜索“IronPDF”。下載包文件(通常是.nupkg文件)。 下載完成後,打開您的項目在Visual Studio中,右鍵單擊“引用”或“依賴項”,選擇“管理NuGet包”。單擊“設置”圖標,然後選擇“添加”來指定您下載的包的路徑。 添加包源後,返回“瀏覽”選項卡,選擇新的源,並從中安裝IronPDF。 5. 使用CraftMyPDF 要在您的C#程序中使用CraftMyPDF,您首先需要創建一個帳戶,選擇API的免費計劃,然後將其集成到您的應用程序中。 以下是您如何開始使用: 5.1. 創建帳戶並選擇免費計劃 註冊:訪問CraftMyPDF網站並註冊免費帳戶。 輸入所需信息以創建您的帳戶。 選擇免費計劃:帳戶創建後,前往定價區並選擇免費計劃。 這個計劃通常允許您使用API的有限功能和配額,非常適合開發和測試用途。 獲取API密鑰:選擇計劃後,轉至您的帳戶儀表板。 在這裡,您將找到您的API密鑰。 此密鑰是驗證您的API請求所必需的。 5.2 安裝所需的庫 確保您具有System.Net.Http, RestSharpt,和Newtonsoft JSON命名空間,因為它是向CraftMyPDF API發送HTTP請求所必需的。 using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using RestSharp; using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using RestSharp; IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 然後將進行CraftMyPDF API的API調用。 var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.Post); string apiKey = "API Key"; // Replace with your actual API key string templateId = "Template ID"; // Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey); request.AddHeader("Content-Type", "application/json"); var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.Post); string apiKey = "API Key"; // Replace with your actual API key string templateId = "Template ID"; // Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey); request.AddHeader("Content-Type", "application/json"); Dim client = New RestClient("https://api.craftmypdf.com/v1/create") Dim request = New RestRequest(Method.Post) Dim apiKey As String = "API Key" ' Replace with your actual API key Dim templateId As String = "Template ID" ' Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey) request.AddHeader("Content-Type", "application/json") $vbLabelText $csharpLabel 6. 創建PDF 程式化創建PDF允許您自動化生成報告、發票和證書等文檔。 IronPDF提供多種方法在C#中創建PDF,包括將HTML字符串、URL和HTML文件轉換為PDF文檔。 我們將在後面的章節中更詳細地討論這些方法。 6.1 使用IronPDF創建PDF 6.1.1 HTML到PDF 將HTML轉換為PDF是最常見的用例之一。 它允許您使用HTML和CSS設計文檔,然後轉換為PDF。 這種方法高度靈活,因為它支持現代網絡標準並確保生成的PDF看起來完全符合設計。 以下是一個使用IronPDF將HTML字符串轉換為PDF文檔的基本示例: using IronPdf; public class PDFCreator { public void CreatePdfFromHtml() { var renderer = new ChromePdfRenderer(); // Define your HTML string string htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>"; // Render the HTML as a PDF document var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF document pdfDocument.SaveAs("html_output.pdf"); } } using IronPdf; public class PDFCreator { public void CreatePdfFromHtml() { var renderer = new ChromePdfRenderer(); // Define your HTML string string htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>"; // Render the HTML as a PDF document var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF document pdfDocument.SaveAs("html_output.pdf"); } } Imports IronPdf Public Class PDFCreator Public Sub CreatePdfFromHtml() Dim renderer = New ChromePdfRenderer() ' Define your HTML string Dim htmlContent As String = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>" ' Render the HTML as a PDF document Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent) ' Save the PDF document pdfDocument.SaveAs("html_output.pdf") End Sub End Class $vbLabelText $csharpLabel 在此示例中,ChromePdfRenderer將提供的HTML字符串轉換為PDF。 生成的PDF隨後保存到文件系統中。 6.1.2 URL到PDF IronPDF的另一個強大功能是能夠直接從其URL轉換網頁為PDF文檔。 這對於存檔網頁或從動態網頁內容生成PDF特別有用。 以下是一個如何將URL轉換為PDF文檔的示例: using IronPdf; public class PDFCreator { public void CreatePdfFromUrl(string url) { // Initialize the ChromePdfRenderer var renderer = new ChromePdfRenderer(); // Render the URL as a PDF document var pdfDocument = renderer.RenderUrlAsPdf(url); // Save the PDF document pdfDocument.SaveAs("url_output.pdf"); } } using IronPdf; public class PDFCreator { public void CreatePdfFromUrl(string url) { // Initialize the ChromePdfRenderer var renderer = new ChromePdfRenderer(); // Render the URL as a PDF document var pdfDocument = renderer.RenderUrlAsPdf(url); // Save the PDF document pdfDocument.SaveAs("url_output.pdf"); } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 此方法以URL為輸入,將網頁渲染為PDF並保存生成的文檔。 它處理所有網頁內容,包括HTML,CSS,JavaScript和圖像,確保PDF準確反映原始網頁。 6.1.3 HTML 文件到PDF 將HTML文件轉換為PDF類似於轉換HTML字符串或URL。 此方法允許您使用本地HTML文件,使其方便從預先存在的網頁或存儲在文件系統上的模板生成PDF。 以下是如何將HTML文件轉換為PDF的示例: using IronPdf; public class PDFCreator { public void CreatePdfFromHtmlFile(string filePath) { // Initialize the ChromePdfRenderer var renderer = new ChromePdfRenderer(); // Render the HTML file as a PDF document var pdfDocument = renderer.RenderHtmlFileAsPdf(filePath); // Save the PDF document pdfDocument.SaveAs("html_file_output.pdf"); } } using IronPdf; public class PDFCreator { public void CreatePdfFromHtmlFile(string filePath) { // Initialize the ChromePdfRenderer var renderer = new ChromePdfRenderer(); // Render the HTML file as a PDF document var pdfDocument = renderer.RenderHtmlFileAsPdf(filePath); // Save the PDF document pdfDocument.SaveAs("html_file_output.pdf"); } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 在此示例中,RenderHtmlFileAsPdf方法被用於將指定文件路徑的HTML文件內容轉換為PDF文檔。 隨後保存生成的PDF。 通過利用這些方法,您可以利用IronPDF從各種HTML內容源創建PDF,為您的C#應用程序提供靈活而強大的文檔生成解決方案。 這些方法確保您可以輕鬆集成PDF創建功能,無論您是處理動態網頁內容、本地HTML文件還是直接定義的HTML字符串。 6.2 使用CraftMyPDF API創建PDF CraftMyPDF提供了一個靈活的API用於從模板生成PDF。 要使用此API創建PDF,您必須首先在CraftMyPDF儀表板中創建一個模板。 模板準備好後,您可以向API發送帶有必要數據的請求以生成PDF。 以下是實現此功能的步驟。 6.2.1 創建模板 登錄CraftMyPDF儀表板:登錄您的CraftMyPDF帳戶並導航至儀表板。 創建新模板:點擊“創建模板”按鈕。 使用拖放編輯器設計您的PDF模板。 您可以根據需要包含文本、圖像、表格和其他元素。 保存模板:一旦滿意設計,保存模板。 然後提供模板ID,生成PDF時您需要使用此模板ID。 6.2.2 發送請求生成PDF 創建模板後,您可以使用以下C#代碼向CraftMyPDF API發送請求以生成PDF。 using System; using System.Net; using System.Threading.Tasks; using RestSharp; class Program { static async Task Main(string[] args) { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.Post); string apiKey = "API-Key"; // Replace with your actual API key string templateId = "Template-ID"; // Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey); request.AddHeader("Content-Type", "application/json"); var body = new { data = new { invoice_number = "INV48321", date = "2024-05-27", due_date = "2024-06-27", currency = "EUR", discount = 10, tax = 5, company_name = "Tech Innovations Ltd", email = "contact@techinnovations.com", client = "Future Solutions GmbH", client_address = "1234 Innovation Drive", client_address2 = "Berlin", client_address3 = "10115", items = new[] { new { description = "Cloud Hosting Services", quantity = 12, unit_price = 75, total = 900 }, new { description = "Custom Web Application", quantity = 3, unit_price = 150, total = 450 }, new { description = "Technical Support", quantity = 15, unit_price = 30, total = 450 }, new { description = "Digital Marketing Campaign", quantity = 2, unit_price = 500, total = 1000 }, new { description = "SEO Optimization", quantity = 5, unit_price = 120, total = 600 } }, gross_total = 3400 }, load_data_from = (string)null, template_id = templateId, version = 8, export_type = "json", expiration = 60, output_file = "output.pdf", is_cmyk = false, image_resample_res = 600, direct_download = 0, cloud_storage = 1 }; request.AddJsonBody(body); RestResponse response = await client.ExecuteAsync(request); Console.WriteLine(response.Content); if (response.IsSuccessful) { var content = response.Content; dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(content); string fileUrl = result.file; string localPath = "f:\\downloaded_output.pdf"; using (WebClient webClient = new WebClient()) { webClient.DownloadFile(fileUrl, localPath); } Console.WriteLine($"PDF downloaded successfully to {localPath}"); } else { Console.WriteLine($"Error: {response.Content}"); } } } using System; using System.Net; using System.Threading.Tasks; using RestSharp; class Program { static async Task Main(string[] args) { var client = new RestClient("https://api.craftmypdf.com/v1/create"); var request = new RestRequest(Method.Post); string apiKey = "API-Key"; // Replace with your actual API key string templateId = "Template-ID"; // Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey); request.AddHeader("Content-Type", "application/json"); var body = new { data = new { invoice_number = "INV48321", date = "2024-05-27", due_date = "2024-06-27", currency = "EUR", discount = 10, tax = 5, company_name = "Tech Innovations Ltd", email = "contact@techinnovations.com", client = "Future Solutions GmbH", client_address = "1234 Innovation Drive", client_address2 = "Berlin", client_address3 = "10115", items = new[] { new { description = "Cloud Hosting Services", quantity = 12, unit_price = 75, total = 900 }, new { description = "Custom Web Application", quantity = 3, unit_price = 150, total = 450 }, new { description = "Technical Support", quantity = 15, unit_price = 30, total = 450 }, new { description = "Digital Marketing Campaign", quantity = 2, unit_price = 500, total = 1000 }, new { description = "SEO Optimization", quantity = 5, unit_price = 120, total = 600 } }, gross_total = 3400 }, load_data_from = (string)null, template_id = templateId, version = 8, export_type = "json", expiration = 60, output_file = "output.pdf", is_cmyk = false, image_resample_res = 600, direct_download = 0, cloud_storage = 1 }; request.AddJsonBody(body); RestResponse response = await client.ExecuteAsync(request); Console.WriteLine(response.Content); if (response.IsSuccessful) { var content = response.Content; dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(content); string fileUrl = result.file; string localPath = "f:\\downloaded_output.pdf"; using (WebClient webClient = new WebClient()) { webClient.DownloadFile(fileUrl, localPath); } Console.WriteLine($"PDF downloaded successfully to {localPath}"); } else { Console.WriteLine($"Error: {response.Content}"); } } } 'INSTANT VB NOTE: 'Option Strict Off' is used here since dynamic typing is used: Option Strict Off Imports System Imports System.Net Imports System.Threading.Tasks Imports RestSharp Friend Class Program Shared Async Function Main(ByVal args() As String) As Task Dim client = New RestClient("https://api.craftmypdf.com/v1/create") Dim request = New RestRequest(Method.Post) Dim apiKey As String = "API-Key" ' Replace with your actual API key Dim templateId As String = "Template-ID" ' Replace with your actual template ID request.AddHeader("X-API-KEY", apiKey) request.AddHeader("Content-Type", "application/json") Dim body = New With { Key .data = New With { Key .invoice_number = "INV48321", Key .date = "2024-05-27", Key .due_date = "2024-06-27", Key .currency = "EUR", Key .discount = 10, Key .tax = 5, Key .company_name = "Tech Innovations Ltd", Key .email = "contact@techinnovations.com", Key .client = "Future Solutions GmbH", Key .client_address = "1234 Innovation Drive", Key .client_address2 = "Berlin", Key .client_address3 = "10115", Key .items = { New With { Key .description = "Cloud Hosting Services", Key .quantity = 12, Key .unit_price = 75, Key .total = 900 }, New With { Key .description = "Custom Web Application", Key .quantity = 3, Key .unit_price = 150, Key .total = 450 }, New With { Key .description = "Technical Support", Key .quantity = 15, Key .unit_price = 30, Key .total = 450 }, New With { Key .description = "Digital Marketing Campaign", Key .quantity = 2, Key .unit_price = 500, Key .total = 1000 }, New With { Key .description = "SEO Optimization", Key .quantity = 5, Key .unit_price = 120, Key .total = 600 } }, Key .gross_total = 3400 }, Key .load_data_from = DirectCast(Nothing, String), Key .template_id = templateId, Key .version = 8, Key .export_type = "json", Key .expiration = 60, Key .output_file = "output.pdf", Key .is_cmyk = False, Key .image_resample_res = 600, Key .direct_download = 0, Key .cloud_storage = 1 } request.AddJsonBody(body) Dim response As RestResponse = Await client.ExecuteAsync(request) Console.WriteLine(response.Content) If response.IsSuccessful Then Dim content = response.Content 'INSTANT VB NOTE: In the following line, Instant VB substituted 'Object' for 'dynamic' - this will work in VB with Option Strict Off: Dim result As Object = Newtonsoft.Json.JsonConvert.DeserializeObject(content) Dim fileUrl As String = result.file Dim localPath As String = "f:\downloaded_output.pdf" Using webClient As New WebClient() webClient.DownloadFile(fileUrl, localPath) End Using Console.WriteLine($"PDF downloaded successfully to {localPath}") Else Console.WriteLine($"Error: {response.Content}") End If End Function End Class $vbLabelText $csharpLabel And it is the generated PDF document by the PDF Generation API CraftMyPdf: Bootstrap 發票生成 專業的發票生成需要現代化、響應式的布局。 此Bootstrap 5示例展示了IronPDF在不使用外部API或模板的情況下創建像素級精確發票的能力。 using IronPdf; var renderer = new ChromePdfRenderer(); string professionalInvoice = @" <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> <style> .invoice-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; } .invoice-table th { background: #f8f9fa; } @media print { .invoice-box { page-break-inside: avoid; } } </style> </head> <body> <div class='container my-4'> <div class='card shadow-lg invoice-box'> <div class='invoice-header p-4'> <div class='row align-items-center'> <div class='col-md-8'> <h1 class='mb-0'>INVOICE</h1> <p class='mb-0 opacity-75'>Invoice #INV-2024-0427</p> </div> <div class='col-md-4 text-md-end'> <h3 class='mb-0'>$3,400.00</h3> <small class='opacity-75'>Due: June 27, 2024</small> </div> </div> </div> <div class='card-body p-4'> <div class='row mb-4'> <div class='col-md-6'> <h6 class='text-primary text-uppercase mb-2'>From</h6> <strong>Tech Innovations Ltd</strong><br> contact@techinnovations.com </div> <div class='col-md-6 text-md-end'> <h6 class='text-primary text-uppercase mb-2'>Bill To</h6> <strong>Future Solutions GmbH</strong><br> 1234 Innovation Drive<br> Berlin, 10115 </div> </div> <table class='table invoice-table'> <thead> <tr> <th>Description</th> <th class='text-center'>Qty</th> <th class='text-end'>Unit Price</th> <th class='text-end'>Total</th> </tr> </thead> <tbody> <tr> <td>Cloud Hosting Services</td> <td class='text-center'>12</td> <td class='text-end'>€75.00</td> <td class='text-end'>€900.00</td> </tr> <tr> <td>Custom Web Application</td> <td class='text-center'>3</td> <td class='text-end'>€150.00</td> <td class='text-end'>€450.00</td> </tr> <tr> <td>Technical Support</td> <td class='text-center'>15</td> <td class='text-end'>€30.00</td> <td class='text-end'>€450.00</td> </tr> <tr> <td>Digital Marketing Campaign</td> <td class='text-center'>2</td> <td class='text-end'>€500.00</td> <td class='text-end'>€1,000.00</td> </tr> <tr> <td>SEO Optimization</td> <td class='text-center'>5</td> <td class='text-end'>€120.00</td> <td class='text-end'>€600.00</td> </tr> </tbody> </table> <div class='row justify-content-end'> <div class='col-md-4'> <table class='table table-sm'> <tr> <td>Subtotal:</td> <td class='text-end'><strong>€3,400.00</strong></td> </tr> <tr> <td>Discount (10%):</td> <td class='text-end text-success'>-€340.00</td> </tr> <tr> <td>Tax (5%):</td> <td class='text-end'>€153.00</td> </tr> <tr class='table-primary'> <td><strong>Total Due:</strong></td> <td class='text-end'><strong>€3,213.00</strong></td> </tr> </table> </div> </div> <div class='alert alert-info mt-4'> <strong>Payment Terms:</strong> Payment due within 30 days. Late payments may incur additional charges. </div> <div class='row mt-4 pt-3 border-top'> <div class='col-md-6'> <small class='text-muted'>Generated with IronPDF - No external APIs required</small> </div> <div class='col-md-6 text-md-end'> <span class='badge bg-success'>PAID</span> </div> </div> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(professionalInvoice); pdf.SaveAs("professional-invoice.pdf"); using IronPdf; var renderer = new ChromePdfRenderer(); string professionalInvoice = @" <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> <style> .invoice-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; } .invoice-table th { background: #f8f9fa; } @media print { .invoice-box { page-break-inside: avoid; } } </style> </head> <body> <div class='container my-4'> <div class='card shadow-lg invoice-box'> <div class='invoice-header p-4'> <div class='row align-items-center'> <div class='col-md-8'> <h1 class='mb-0'>INVOICE</h1> <p class='mb-0 opacity-75'>Invoice #INV-2024-0427</p> </div> <div class='col-md-4 text-md-end'> <h3 class='mb-0'>$3,400.00</h3> <small class='opacity-75'>Due: June 27, 2024</small> </div> </div> </div> <div class='card-body p-4'> <div class='row mb-4'> <div class='col-md-6'> <h6 class='text-primary text-uppercase mb-2'>From</h6> <strong>Tech Innovations Ltd</strong><br> contact@techinnovations.com </div> <div class='col-md-6 text-md-end'> <h6 class='text-primary text-uppercase mb-2'>Bill To</h6> <strong>Future Solutions GmbH</strong><br> 1234 Innovation Drive<br> Berlin, 10115 </div> </div> <table class='table invoice-table'> <thead> <tr> <th>Description</th> <th class='text-center'>Qty</th> <th class='text-end'>Unit Price</th> <th class='text-end'>Total</th> </tr> </thead> <tbody> <tr> <td>Cloud Hosting Services</td> <td class='text-center'>12</td> <td class='text-end'>€75.00</td> <td class='text-end'>€900.00</td> </tr> <tr> <td>Custom Web Application</td> <td class='text-center'>3</td> <td class='text-end'>€150.00</td> <td class='text-end'>€450.00</td> </tr> <tr> <td>Technical Support</td> <td class='text-center'>15</td> <td class='text-end'>€30.00</td> <td class='text-end'>€450.00</td> </tr> <tr> <td>Digital Marketing Campaign</td> <td class='text-center'>2</td> <td class='text-end'>€500.00</td> <td class='text-end'>€1,000.00</td> </tr> <tr> <td>SEO Optimization</td> <td class='text-center'>5</td> <td class='text-end'>€120.00</td> <td class='text-end'>€600.00</td> </tr> </tbody> </table> <div class='row justify-content-end'> <div class='col-md-4'> <table class='table table-sm'> <tr> <td>Subtotal:</td> <td class='text-end'><strong>€3,400.00</strong></td> </tr> <tr> <td>Discount (10%):</td> <td class='text-end text-success'>-€340.00</td> </tr> <tr> <td>Tax (5%):</td> <td class='text-end'>€153.00</td> </tr> <tr class='table-primary'> <td><strong>Total Due:</strong></td> <td class='text-end'><strong>€3,213.00</strong></td> </tr> </table> </div> </div> <div class='alert alert-info mt-4'> <strong>Payment Terms:</strong> Payment due within 30 days. Late payments may incur additional charges. </div> <div class='row mt-4 pt-3 border-top'> <div class='col-md-6'> <small class='text-muted'>Generated with IronPDF - No external APIs required</small> </div> <div class='col-md-6 text-md-end'> <span class='badge bg-success'>PAID</span> </div> </div> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(professionalInvoice); pdf.SaveAs("professional-invoice.pdf"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 輸出:一個具有Bootstrap 5漸變頁眉、響應式表格和計算摘要的專業發票PDF。 IronPDF完美準確地渲染所有CSS漸變、表格樣式和實用類—無需外部API調用,無需模板,無需互聯網連接。 與CraftMyPDF的雲端方法不同,IronPDF在您的服務器上瞬間生成發票,具有完整控制權。 有關Bootstrap表格支持的更多信息,請參閱Bootstrap & Flexbox CSS指南。 代碼解釋 設置RestClient和RestRequest:用CraftMyPDF API URL實例化RestClient,並創建POST方法的RestRequest以生成PDF。 添加標頭:將API密鑰添加到請求標頭以進行身份驗證。 內容類型設置為application/json。 準備請求正文:將請求正文創建為JSON對象。 它包括用於填充模板字段的數據、模板ID和各種選項,如導出類型和到期時間。 發送請求:使用ExecuteAsync異步發送請求,並基於請求正文生成PDF文檔。 處理響應:如果響應成功,從響應中提取生成PDF文件的URL,並使用WebClient將文件下載到本地路徑。 如果請求失敗,將打印錯誤信息。 7. 許可證 IronPDF提供多種許可證選項,以滿足不同用戶的需求。 主要許可證包括Lite、Professional和Enterprise版本。 Lite許可證的價格為$799,適合單一開發人員的單一項目。 Professional許可證價格為$1,199,支持多個項目和開發人員,而Enterprise許可證則適合更大的團隊和更廣泛的部署,價格為$2,399。 每個許可證都是一次性費用,包括一年的支持和更新。 此外,還有OEM再分發許可證,允許將IronPDF作為商業產品的一部分進行分發。 IronPDF還提供免費試用供評估使用。 CraftMyPDF運行的是基於訂閱的許可證模式。 它提供多個計劃,包括適合小規模和開發用途的免費層。 免費計劃允許有限地使用API,非常適合測試和小項目。 為了更高的使用需求,還有付費計劃,提供更多的API調用限制和額外功能。 這些付費計劃旨在隨著業務需求的增長提供擴展性和穩固的支持。 用戶需通過CraftMyPDF網站訂閱這些計劃,並通過用戶儀表板管理訂閱和API密鑰。 8. 文檔和支持 8.1 IronPDF的文件和支持 IronPDF提供豐富的文件和強大的支持,幫助用戶有效地利用該庫。 文檔是全面的,包括詳細指南、示例和快速入門部分,旨在幫助新用戶快速上手。 關鍵部分涵蓋基本用法、高級配置和故障排除。 此外,IronPDF還通過多個渠道提供支持,包括豐富的知識庫、電子郵件支持和更複雜問題的工程支持請求。 支持團隊提供24/5的服務,迅速解決用戶的要求和問題。 8.2 CraftMyPdf指南和支持 CraftMyPDF也為其用戶提供詳盡的文檔和支持。 API文檔提供了有關所有可用端點、參數和示例請求的詳細信息,確保開發人員可以順利集成API。 文檔包括關於創建模板、發送API請求和處理響應的指南。 CraftMyPDF通過電子郵件提供客戶支持,並提供一個社區論壇,用戶可以在那裡提問和分享見解。 文檔旨在讓所有技術水平的開發人員友好使用,確保能夠有效利用API生成PDF。 9. 結論 在本文中,我們探討了兩種強大的PDF生成工具的功能、許可證和文檔:IronPDF和CraftMyPDF。 這兩個工具都提供了創建和管理PDF文檔的強大功能,但IronPDF有一些顯著的優勢。 IronPDF提供了廣泛的功能來滿足各種PDF生成需求,包括將HTML字符串、URL和HTML文件輕鬆轉換為PDF。 它與.NET環境的無縫集成和處理複雜文檔結構的能力使其成為一個高效的工具。 此外,IronPDF支持高級選項,如添加頁眉和頁腳、數字簽名和處理PDF表單,確保它能滿足各類應用程序的需求。 IronPDF的一個重大優勢是其許可證結構。 它提供免費試用,允許用戶在購買之前評估軟件。 許可證從$799開始,使其對於個人開發人員和小團隊具有可及性。 此外,IronPDF通過提供Iron Suite提供了極具價值的方案,該方案包含九種產品,價格等於兩種,非常具成本效益,適合全面PDF和文件管理需求。 總之,儘管IronPDF和CraftMyPDF都是出色的PDF生成工具,但IronPDF提供了更廣泛的功能集、強大的支持和更有利的許可證模式。 它處理複雜文檔需求的能力以及具成本效益的Iron Suite套餐使其在CraftMyPDF之上具有優勢。 無論您是個人開發人員還是大型團隊的一部分,IronPDF為您的所有PDF生成需求提供了一個可靠而強大的解決方案。 請注意CraftMyPDF 是其相應所有者的註冊商標 本站與CraftMyPDF無關,也不被其認可或贊助。 所有產品名稱、徽標和品牌均為其各自所有者的財產。 比較僅供信息參考,並反映撰寫時公開可用的信息。 常見問題解答 使用 C# PDF 库相比基于 API 的解决方案有哪些优势? 像 IronPDF 这样全面的 PDF 库提供了丰富的功能、与 .NET 开发环境的无缝集成、强大的支持和成本效益高的许可选项,使其成为复杂文档处理的优越选择。 如何使用 C# 将 HTML 内容转换为 PDF 文档? 您可以使用 IronPDF 将 HTML 内容转换为 PDF 文档。它支持 HTML5 和 CSS3,确保网页内容在生成的 PDF 中准确呈现。 IronPDF 在 PDF 生成中突出了哪些功能? IronPDF 提供数字签名、表单填写、PDF 编辑、注释和跨平台兼容性。它在将 HTML、URL 和图像转换为 PDF 时表现出色,并具有强大的性能和优化。 CraftMyPDF 如何处理 PDF 模板设计? CraftMyPDF 提供基于网页的拖放编辑器,允许用户在不需要编码的情况下设计 PDF 模板。它支持 JSON 数据集成,能够创建定制的 PDF 文档。 像 IronPDF 这样的 PDF 工具有哪些许可选项? IronPDF 提供灵活的许可选项,包括 Lite、Professional 和 Enterprise 许可证,一次性费用。它还为新用户提供免费试用,以探索其功能。 如何将 PDF 生成 API 集成到我的 C# 应用程序中? 要集成像 CraftMyPDF 这样的 PDF 生成 API,您需要创建账户,选择适当的计划,获取 API 密钥,并使用诸如 System.Net.Http 和 RestSharp 的库进行 API 调用。 使用 IronPDF 的开发者有哪些支持资源可用? IronPDF 提供丰富的文档、教程和 24/5 技术支持。这些资源帮助开发者在他们的项目中有效地实现和排除库的故障。 如何在 C# 应用程序中安装 IronPDF? 可以通过 Visual Studio 中的 NuGet 软件包管理器安装 IronPDF,或者通过 NuGet 软件包管理器控制台安装,也可以从 NuGet 网站直接下载软件包。 IronPDF 如何增强 PDF 文档的安全性和互动性? IronPDF 支持数字签名和表单处理等功能,这些功能提高了文档的安全性和互动性,使其适合全面的 PDF 管理。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 發表日期 11月 13, 2025 C# HTML 與 PDF 開源版本比較 IronPDF 將開源 HTML 轉 PDF 庫與 IronPDF for C# 進行比較。探索哪種解決方案能為您的 .NET 專案提供最佳的 PDF 生成功能。 閱讀更多 發表日期 10月 27, 2025 哪個 ASP.NET Core PDF 庫具有最佳價值? 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多 發表日期 10月 27, 2025 如何使用 Aspose C# 和 IronPDF 創建 PDF 通過這份針對開發人員設計的分步指南,學習如何使用 Aspose C# 與 IronPDF 創建 PDF。 閱讀更多 C#中HTML到PDF轉換器GroupDocs的替代方案Compdfkit與IronPDF之間的比較
發表日期 11月 13, 2025 C# HTML 與 PDF 開源版本比較 IronPDF 將開源 HTML 轉 PDF 庫與 IronPDF for C# 進行比較。探索哪種解決方案能為您的 .NET 專案提供最佳的 PDF 生成功能。 閱讀更多
發表日期 10月 27, 2025 哪個 ASP.NET Core PDF 庫具有最佳價值? 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多
發表日期 10月 27, 2025 如何使用 Aspose C# 和 IronPDF 創建 PDF 通過這份針對開發人員設計的分步指南,學習如何使用 Aspose C# 與 IronPDF 創建 PDF。 閱讀更多