使用IRONPDF C#生成文件的PDF比較7個庫(免費及付費工具) Curtis Chau 更新日期:9月 18, 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 的工具,使其成為基礎 PDF 任務的多功能工具。 In this article, we will explore six popular ways to generate PDF files using C#, highlighting both code-based libraries, such as IronPDF, and online APIs and tools. 這使其非常適合需要快速從各種文檔類型創建 PDF 的用戶。 合併和拆分 PDF:提供簡單的界面將多個 PDF 合併為一個文件或將 PDF 拆分為單個頁面。 雲存儲集成:您可以輕鬆地從 Google 雲端硬盤或 Dropbox 上傳文件,並將轉換後的 PDF 保存回這些平台,簡化文件管理。 - PDF 編輯工具:提供基本的 PDF 編輯工具來編輯任何現有的 PDF 文檔,例如添加註釋、填寫表單或數字簽署文件。 - 對非開發人員來說非常容易使用。 免費使用基本功能,並可選擇升級以獲得更多功能。 - 提供各種與 PDF 相關的工具,如合併、拆分和壓縮 PDF。 與基於代碼的解決方案相比,自定義有限。 免費層可能有一些功能限制。 ### 7.2. PDFescape PDFescape 是一款易於使用的基於 Web 的 PDF 編輯器,允許用戶創建、編輯和查看 PDF,而無需安裝任何軟件。 對於需要進行快速 PDF 編輯的人,如填寫表單、添加文本註釋或插入圖像,是一個很好的工具。 PDFescape 還提供從頭創建新 PDF 的工具,使其成為基本文檔創建的靈活選擇。 表單填寫和編輯:在處理 PDF 表單方面表現出色。 用戶可以輕鬆填寫表單或編輯 PDF 文檔中現有的字段,這對於合同、申請和其他表單非常有用。 基本 PDF 創建:提供添加文本、形狀、圖像和表單字段的工具。 using IronPdf; class Program { static void Main() { string html = "<h1>Hello, World!</h1><p>This PDF is generated from HTML.</p>"; // Create an instance of ChromePdfRenderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render the HTML as a PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf(html); // Save the PDF to a specified file pdf.SaveAs("Generated.pdf"); } } using IronPdf; class Program { static void Main() { string html = "<h1>Hello, World!</h1><p>This PDF is generated from HTML.</p>"; // Create an instance of ChromePdfRenderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render the HTML as a PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf(html); // Save the PDF to a specified file pdf.SaveAs("Generated.pdf"); } } Imports IronPdf Friend Class Program Shared Sub Main() Dim html As String = "<h1>Hello, World!</h1><p>This PDF is generated from HTML.</p>" ' Create an instance of ChromePdfRenderer Dim renderer As New ChromePdfRenderer() ' Render the HTML as a PDF document Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html) ' Save the PDF to a specified file pdf.SaveAs("Generated.pdf") End Sub End Class $vbLabelText $csharpLabel 對於創建簡單的文檔如信件或表單很有用。 註釋和評論:向現有 PDF 添加評論、便簽和其他註釋,使 PDFescape 成為文檔審核和合作的好工具。 無需安裝:完全在瀏覽器中運行,因此無需安裝任何軟件。 這使其對需要快速訪問 PDF 工具的用戶來說非常理想。 易於非技術用戶使用。 免費層提供基本的 PDF 創建和編輯。 適合進行小型 PDF 編輯任務。 缺乏複雜的 PDF 創建的高級功能。 設計和格式選項有限。 7.3. PDF Candy PDF Candy 是一套免費的在線 PDF 工具,涵蓋從文件轉換到編輯的廣泛的 PDF 相關任務。 對於需要在不註冊帳戶或安裝軟件的情況下執行快速 PDF 操作的用戶來說,是一個絕佳選擇。 PDF Candy 支持將各種文件類型(如 Word 文檔、圖像和文本文件)轉換為 PDF。 它還提供合併、拆分和壓縮 PDF 的工具。 - 廣泛的轉換選項:能夠將多種格式,包括 Word 文檔、圖像和文本文件,轉換為 PDF。 這使其成為一個靈活的工具來處理不同類型的內容。 與基於代碼的解決方案相比,自定義有限。 合併和拆分 PDF:允許用戶將多個 PDF 合併為一個或將大型 PDF 拆分為更小、更易管理的文件。 - 文件私隱:自動在短時間後從其服務器中刪除文件,確保您的文件保密。 免費使用:大多數工具可免費使用,無需註冊,讓廣大受眾可以輕鬆使用。 然而,對於需要更頻繁使用或更大文件轉換的人,還提供具有更多高級功能的高級版本。 易於使用,對大多數用戶完全免費。 - 支持多種文件類型轉換為 PDF。 基本使用無需帳戶註冊。 高級 PDF 自定義功能有限。 基本 PDF 創建:提供添加文本、形狀、圖像和表單字段的工具。 using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.tool.xml; namespace Helpers { public class PdfGenerator { public static byte[] GeneratePdfFromFragment(string htmlFragment) { var html = string.Format(@" <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <style type='text/css'> table,td {{border: 1px solid black;}} div {{ white-space: nowrap; padding: 2px;}} table{{ border-collapse: collapse; width: 100%; empty-cells: show;}} body table {{font-size: 50%;}} th {{width:500px; height: 28px;}} td {{width:300px; height: 28px;}} </style> </head><body>{0}</body></html>", htmlFragment); return Generate(html); } public static byte[] GeneratePdfFromPage(string htmlPage) { return Generate(htmlPage); } private static byte[] Generate(string html) { using (var memoryStream = new MemoryStream()) { var pdfDocument = new Document(PageSize.LETTER); var pdfWriter = PdfWriter.GetInstance(pdfDocument, memoryStream); pdfDocument.Open(); using (var fw = new StringReader(html)) { XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, pdfDocument, fw); } pdfDocument.Close(); return memoryStream.ToArray(); } } } } using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.tool.xml; namespace Helpers { public class PdfGenerator { public static byte[] GeneratePdfFromFragment(string htmlFragment) { var html = string.Format(@" <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <style type='text/css'> table,td {{border: 1px solid black;}} div {{ white-space: nowrap; padding: 2px;}} table{{ border-collapse: collapse; width: 100%; empty-cells: show;}} body table {{font-size: 50%;}} th {{width:500px; height: 28px;}} td {{width:300px; height: 28px;}} </style> </head><body>{0}</body></html>", htmlFragment); return Generate(html); } public static byte[] GeneratePdfFromPage(string htmlPage) { return Generate(htmlPage); } private static byte[] Generate(string html) { using (var memoryStream = new MemoryStream()) { var pdfDocument = new Document(PageSize.LETTER); var pdfWriter = PdfWriter.GetInstance(pdfDocument, memoryStream); pdfDocument.Open(); using (var fw = new StringReader(html)) { XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, pdfDocument, fw); } pdfDocument.Close(); return memoryStream.ToArray(); } } } } Imports System Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf Imports iTextSharp.tool.xml Namespace Helpers Public Class PdfGenerator Public Shared Function GeneratePdfFromFragment(ByVal htmlFragment As String) As Byte() Dim html = String.Format(" <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <style type='text/css'> table,td {{border: 1px solid black;}} div {{ white-space: nowrap; padding: 2px;}} table{{ border-collapse: collapse; width: 100%; empty-cells: show;}} body table {{font-size: 50%;}} th {{width:500px; height: 28px;}} td {{width:300px; height: 28px;}} </style> </head><body>{0}</body></html>", htmlFragment) Return Generate(html) End Function Public Shared Function GeneratePdfFromPage(ByVal htmlPage As String) As Byte() Return Generate(htmlPage) End Function Private Shared Function Generate(ByVal html As String) As Byte() Using memoryStream As New MemoryStream() Dim pdfDocument = New Document(PageSize.LETTER) Dim pdfWriter = PdfWriter.GetInstance(pdfDocument, memoryStream) pdfDocument.Open() Using fw = New StringReader(html) XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, pdfDocument, fw) End Using pdfDocument.Close() Return memoryStream.ToArray() End Using End Function End Class End Namespace $vbLabelText $csharpLabel 某些工具可能對文件大小或轉換複雜性有限制。 選擇在 C# 中生成 PDF 文件的正確工具取決於您的需求。 如果需要從 HTML 內容生成 PDF 文檔,IronPDF 和 PDFShift 是極好的選擇。 iTextSharp 和 Syncfusion 提供廣泛的自定義選項和對文檔結構的控制,適合更複雜的項目。 對於更簡單的開源解決方案,PDFsharp 是修改 PDF 文件或創建基本 PDF 的可靠選擇。 最後,對於非開發人員,Smallpdf、PDFescape 和 PDF Candy 提供簡單的、無需代碼的選擇來處理 PDF 文件。 免費層提供基本的 PDF 創建和編輯。 對於那些有興趣嘗試 [IronPDF](trial license) 的人,這是開發者測試其 HTML 到 PDF 轉換和 PDF 操作功能的極佳選擇,然後再承諾付費許可。 試用版讓您探索其高級功能,如高質量的 PDF 文件生成、安全選項和修改現有 PDF 文檔,讓您親身體驗這款工具的能力。 設計和格式選項有限。 如果您的項目需要頻繁的 HTML 到 PDF 轉換或複雜的 PDF 編輯,IronPDF 的免費試用是一個了解其是否符合您的需求的好方法。 通過評估每個工具的特定特徵和您項目的範圍,您可以選擇在 C# 中有效生成 PDF 文件的最佳解決方案。 iText7 (the newer version of iText) uses a more robust HTML parser, pdfHTML, that might provide better support for modern web standards. Steeper learning curve for beginners. 3. PDFsharp PDFSharp is a lightweight, open-source .NET PDF library ideal for basic PDF creation tasks. If your application requires only simple operations like adding text, images, or tables, PDFSharp is an easy-to-use option for generating PDF documents in C#. It lacks advanced features like HTML to PDF conversion but shines in its simplicity for generating small to medium-sized PDF files in C#. 與基於代碼的解決方案相比,自定義有限。 Basic PDF Creation: Simple and easy-to-use API for drawing text and graphics. Ideal for creating straightforward documents. Document Manipulation: Merge and modify existing PDFs with ease, allowing for flexibility in document management. Drawing and Graphics Support: PDFsharp provides a set of tools for drawing on PDF pages, including lines, rectangles, and other vector graphics. It also supports embedding images into your PDFs. Free and Open-Source: PDFsharp is completely free for commercial and non-commercial use, making it an attractive option for small businesses and developers working on open-source projects. 基本 PDF 創建:提供添加文本、形狀、圖像和表單字段的工具。 using PdfSharp.Pdf; using PdfSharp.Drawing; class Program { static void Main() { // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PdfSharp"; // Add a page to the document PdfPage page = document.AddPage(); // Create an XGraphics object to draw on the page XGraphics gfx = XGraphics.FromPdfPage(page); // Set a font to use for drawing text XFont font = new XFont("Verdana", 20, XFontStyle.Bold); // Draw the text on the PDF page gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); // Save the document to disk document.Save("Generated.pdf"); } } using PdfSharp.Pdf; using PdfSharp.Drawing; class Program { static void Main() { // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PdfSharp"; // Add a page to the document PdfPage page = document.AddPage(); // Create an XGraphics object to draw on the page XGraphics gfx = XGraphics.FromPdfPage(page); // Set a font to use for drawing text XFont font = new XFont("Verdana", 20, XFontStyle.Bold); // Draw the text on the PDF page gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); // Save the document to disk document.Save("Generated.pdf"); } } Imports PdfSharp.Pdf Imports PdfSharp.Drawing Friend Class Program Shared Sub Main() ' Create a new PDF document Dim document As New PdfDocument() document.Info.Title = "Created with PdfSharp" ' Add a page to the document Dim page As PdfPage = document.AddPage() ' Create an XGraphics object to draw on the page Dim gfx As XGraphics = XGraphics.FromPdfPage(page) ' Set a font to use for drawing text Dim font As New XFont("Verdana", 20, XFontStyle.Bold) ' Draw the text on the PDF page gfx.DrawString("Hello, World!", font, XBrushes.Black, New XRect(0, 0, page.Width, page.Height), XStringFormats.Center) ' Save the document to disk document.Save("Generated.pdf") End Sub End Class $vbLabelText $csharpLabel PdfDocument: Represents the entire PDF document. You can add pages, set metadata, and manipulate the document. PdfPage: Represents a single page within the document. New pages are added using the AddPage method. XGraphics: Used to draw text, images, and shapes on a specific page. It’s similar to GDI+ in .NET. XFont: Specifies the font and style for text rendering. In this example, "Verdana" is used with bold styling. DrawString: Draws the specified string at the defined position within the document. 免費層提供基本的 PDF 創建和編輯。 Free and open-source with no licensing restrictions. Simple and lightweight, making it easy to get started with basic PDF generation. Works well for projects that don’t require complex features. 設計和格式選項有限。 Limited functionality compared to other libraries. No native support for converting HTML to PDF. 4. Syncfusion PDF Library Syncfusion PDF Library is a high-performance, comprehensive tool designed for enterprises that need to work with PDFs in a wide range of applications. It’s part of the broader Syncfusion suite, which offers libraries for a variety of formats and platforms. The PDF library stands out because of its extensive feature set that goes beyond simple document creation and allows for detailed manipulation, including form filling, digital signatures, and document security. 與基於代碼的解決方案相比,自定義有限。 Comprehensive PDF API: Capable of generating highly customized PDFs, including those with complex layouts, embedded fonts, and high-resolution images. Provides detailed control over all aspects of PDF creation, from page formatting to advanced layout options. Form Processing: The library excels at creating, filling, and extracting data from interactive PDF forms (AcroForms). Useful for creating fillable PDFs for user input, automating data entry, or processing filled forms. Digital Signatures and Encryption: Offers robust security features, including the ability to encrypt PDF documents, add password protection, and apply digital signatures. Essential for industries like healthcare and legal services that require document authenticity and security. 基本 PDF 創建:提供添加文本、形狀、圖像和表單字段的工具。 using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; class Program { static void Main() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Add a page to the document. PdfPage page = document.Pages.Add(); // Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; // Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); // Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); // Save the document. document.Save("Output.pdf"); // Close the document. document.Close(true); } } using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; class Program { static void Main() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Add a page to the document. PdfPage page = document.Pages.Add(); // Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; // Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); // Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); // Save the document. document.Save("Output.pdf"); // Close the document. document.Close(true); } } Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Graphics Friend Class Program Shared Sub Main() ' Create a new PDF document. Dim document As New PdfDocument() ' Add a page to the document. Dim page As PdfPage = document.Pages.Add() ' Create PDF graphics for the page. Dim graphics As PdfGraphics = page.Graphics ' Set the standard font. Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20) ' Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0)) ' Save the document. document.Save("Output.pdf") ' Close the document. document.Close(True) End Sub End Class $vbLabelText $csharpLabel PdfDocument: Represents the PDF document. You can add pages, set properties, and manipulate its content. PdfPage: Represents a page within the PDF document. PdfFont: Defines the font for rendering text. In this case, a standard Helvetica font is used. DrawString: Draws the specified string onto the PDF page at the given coordinates. 免費層提供基本的 PDF 創建和編輯。 Rich feature set, suitable for creating complex PDFs. Professional support and documentation make it ideal for large-scale applications. Supports advanced PDF capabilities like form filling, encryption, and annotations. 設計和格式選項有限。 Licensing fees are relatively high for commercial use. Complex API, which may require time to master. 5. PDFShift (Online Tool) PDFShift is a cloud-based service designed to convert HTML into PDF files. It integrates smoothly with C# applications via its API, allowing you to convert dynamically generated HTML web pages into professional-quality PDFs. PDFShift is particularly useful for web developers who want to generate PDF documents on demand from HTML content, such as invoices or reports. Since PDFShift operates entirely through its REST API, you can send just a few lines of HTML to the service and receive a downloadable PDF file in return. It’s a simple, scalable solution for web-based PDF file generation. 與基於代碼的解決方案相比,自定義有限。 HTML to PDF Conversion: PDFShift excels at converting HTML documents into high-quality PDFs. It handles complex CSS styles, JavaScript, and responsive design layouts, ensuring that your web page looks exactly the same in PDF format. API Integration: The PDFShift API is designed for seamless integration into web applications. It’s straightforward to use: simply send an HTTP POST request with the HTML content, and the service returns a PDF document. Customization Options: Allows for customization of the generated PDF, including setting page size, orientation, margins, and headers/footers. You can also add dynamic content to the headers and footers, such as page numbers or document metadata. How It Works Send a POST request with HTML content to the PDFShift API endpoint. Receive the generated PDF in response, ready to download or save. Example Code using System.Net.Http; using System.Text; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { string htmlContent = "<h1>Hello, World!</h1><p>This is generated using PDFShift API.</p>"; var content = new StringContent(htmlContent, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://api.pdfshift.io/v3/convert", content); byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync(); System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes); } } } using System.Net.Http; using System.Text; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { string htmlContent = "<h1>Hello, World!</h1><p>This is generated using PDFShift API.</p>"; var content = new StringContent(htmlContent, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://api.pdfshift.io/v3/convert", content); byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync(); System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes); } } } Imports System.Net.Http Imports System.Text Imports System.Threading.Tasks Friend Class Program Shared Async Function Main(ByVal args() As String) As Task Using client As New HttpClient() Dim htmlContent As String = "<h1>Hello, World!</h1><p>This is generated using PDFShift API.</p>" Dim content = New StringContent(htmlContent, Encoding.UTF8, "application/json") Dim response As HttpResponseMessage = Await client.PostAsync("https://api.pdfshift.io/v3/convert", content) Dim pdfBytes() As Byte = Await response.Content.ReadAsByteArrayAsync() System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes) End Using End Function End Class $vbLabelText $csharpLabel HttpClient: Sends the HTML content as a POST request to the PDFShift API. PostAsync: Sends the request to the API, which processes the HTML and returns the PDF. ReadAsByteArrayAsync: Reads the PDF response as a byte array, which can then be saved as a file. 免費層提供基本的 PDF 創建和編輯。 Simple API with minimal setup. Ideal for web applications that require dynamic HTML to PDF conversion. No need to manage PDF libraries or servers. 設計和格式選項有限。 Limited to HTML to PDF conversion; doesn’t support more complex PDF features. Requires an internet connection and incurs costs after a certain usage threshold. 6. DocRaptor (Online Tool) DocRaptor is another powerful API-based PDF generation service that converts HTML and CSS into high-quality PDFs. It is known for its excellent rendering of HTML documents, particularly in handling complex CSS styles, media queries, and web fonts. This makes DocRaptor a great choice for generating professional-looking documents like reports, invoices, and eBooks, directly from HTML templates. 與基於代碼的解決方案相比,自定義有限。 HTML and CSS Support: Converts HTML documents with complex CSS styles, including media queries and fonts. API Integration: REST API for seamless integration into web applications. Custom Headers/Footers: Add dynamic headers and footers, including page numbers and custom formatting. PDF Security: Supports encryption and password protection. How It Works Send a POST request to the DocRaptor API with HTML content. Customize the PDF output with parameters for page size, margins, headers, and footers. Receive the generated PDF in response. Example Code using System.Net.Http; using System.Text; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { string apiKey = "YOUR_API_KEY"; string htmlContent = "<h1>Professional Report</h1><p>Generated using DocRaptor API.</p>"; string jsonData = $"{{\"test\": true, \"document_content\": \"{htmlContent}\", \"name\": \"Generated.pdf\", \"document_type\": \"pdf\"}}"; var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync($"https://docraptor.com/docs?user_key={apiKey}", content); byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync(); System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes); } } } using System.Net.Http; using System.Text; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { string apiKey = "YOUR_API_KEY"; string htmlContent = "<h1>Professional Report</h1><p>Generated using DocRaptor API.</p>"; string jsonData = $"{{\"test\": true, \"document_content\": \"{htmlContent}\", \"name\": \"Generated.pdf\", \"document_type\": \"pdf\"}}"; var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync($"https://docraptor.com/docs?user_key={apiKey}", content); byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync(); System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes); } } } Imports System.Net.Http Imports System.Text Imports System.Threading.Tasks Friend Class Program Shared Async Function Main(ByVal args() As String) As Task Using client As New HttpClient() Dim apiKey As String = "YOUR_API_KEY" Dim htmlContent As String = "<h1>Professional Report</h1><p>Generated using DocRaptor API.</p>" Dim jsonData As String = $"{{""test"": true, ""document_content"": ""{htmlContent}"", ""name"": ""Generated.pdf"", ""document_type"": ""pdf""}}" Dim content = New StringContent(jsonData, Encoding.UTF8, "application/json") Dim response As HttpResponseMessage = Await client.PostAsync($"https://docraptor.com/docs?user_key={apiKey}", content) Dim pdfBytes() As Byte = Await response.Content.ReadAsByteArrayAsync() System.IO.File.WriteAllBytes("Generated.pdf", pdfBytes) End Using End Function End Class $vbLabelText $csharpLabel API Key: You must provide an API key for authentication when using DocRaptor. Replace "YOUR_API_KEY" with your actual key. JsonData: This JSON string contains the HTML content, document name, and type (PDF in this case). PostAsync: Sends the HTML content and parameters to the DocRaptor API for PDF generation. 免費層提供基本的 PDF 創建和編輯。 High-quality rendering with full support for HTML, CSS, and JavaScript. Advanced customization options for document layout and security. No need to maintain PDF generation libraries or infrastructure. 設計和格式選項有限。 Paid service after exceeding a free usage limit. Dependent on internet connectivity. 7. Code-Free Online Tools If you don’t want to write code or need a quick solution for generating PDFs, several online tools allow you to create PDFs quickly and easily. Here are a few notable options: 7.1. Smallpdf Smallpdf is an online platform offering a variety of PDF-related tools, including the ability to create PDFs from a wide range of file formats. It’s designed for users who want a simple drag-and-drop interface without needing to write code. Smallpdf is widely used for quick file conversions, such as turning Word documents, Excel sheets, or images into PDFs. It also provides tools for merging, compressing, and splitting PDFs, making it a versatile tool for basic PDF tasks. 與基於代碼的解決方案相比,自定義有限。 File Conversion: Supports converting Word, Excel, PowerPoint, and image files (JPG, PNG) into PDF. This makes it ideal for users who need to create PDFs from a variety of document types quickly. Merging and Splitting PDFs: Offers a simple interface for merging multiple PDFs into a single file or splitting a PDF into individual pages. Cloud Storage Integration: You can easily upload files from Google Drive or Dropbox and save the converted PDFs back to these platforms, streamlining file management. PDF Editing Tools: Provides basic PDF editing tools to edit any existing PDF document, such as adding annotations, filling out forms, and signing documents digitally. 免費層提供基本的 PDF 創建和編輯。 Very easy to use for non-developers. Free for basic usage with options to upgrade for more features. Offers a wide variety of PDF-related tools like merging, splitting, and compressing PDFs. 設計和格式選項有限。 Limited customization compared to code-based solutions. Free tier may have some feature restrictions. 7.2. PDFescape PDFescape is an easy-to-use web-based PDF editor that allows users to create, edit, and view PDFs without the need for installing any software. It’s a great tool for those who need to make quick edits to PDFs, such as filling out forms, adding text annotations, or inserting images. PDFescape also offers tools for creating new PDFs from scratch, making it a flexible choice for basic document creation. 與基於代碼的解決方案相比,自定義有限。 Form Filling and Editing: Excels in handling PDF forms. Users can easily fill out forms or edit existing fields in PDF documents, useful for contracts, applications, and other forms. Basic PDF Creation: Offers tools to add text, shapes, images, and form fields. Useful for creating simple documents like letters or forms. Annotations and Comments: Add comments, sticky notes, and other annotations to existing PDFs, making PDFescape a great tool for document review and collaboration. No Installation Required: Works entirely in your browser, so there’s no need to install any software. This makes it ideal for users who need quick access to PDF tools on the go. 免費層提供基本的 PDF 創建和編輯。 Simple to use for non-technical users. Free tier for basic PDF creation and editing. Suitable for minor PDF editing tasks. 設計和格式選項有限。 Lacks advanced features for complex PDF creation. Limited design and formatting options. 7.3. PDF Candy PDF Candy is a suite of free online PDF tools that covers a wide range of PDF-related tasks, from file conversion to editing. It’s an excellent choice for users who need to perform quick PDF operations without registering for an account or installing software. PDF Candy supports converting various file types, such as Word documents, images, and text files, into PDFs. It also provides tools for merging, splitting, and compressing PDFs. 與基於代碼的解決方案相比,自定義有限。 Wide Range of Conversion Options: Can convert multiple file formats, including Word documents, images, and text files, into PDFs. This makes it a flexible tool for handling different types of content. Merging and Splitting PDFs: Allows users to merge multiple PDFs into one or split large PDFs into smaller, more manageable files. File Privacy: Automatically deletes files from its servers after a short period, ensuring that your documents remain private. Free to Use: Most tools are free to use without registration, making it accessible to a wide audience. However, it also offers a premium version with more advanced features for those who need more frequent use or larger file conversions. 免費層提供基本的 PDF 創建和編輯。 Easy to use and completely free for most users. Supports a variety of file types for conversion to PDF. No account registration required for basic usage. 設計和格式選項有限。 Limited advanced PDF customization features. Some tools may have restrictions on file size or conversion complexity. 結論 Choosing the right tool to generate PDF files in C# depends on your needs. If you need to generate PDF documents from HTML content, IronPDF and PDFShift are excellent choices. iTextSharp and Syncfusion offer extensive customization options and control over document structure for more complex projects. For simpler, open-source solutions, PDFsharp is a reliable choice for modifying PDF files or creating basic PDFs. Finally, for non-developers, Smallpdf, PDFescape, and PDF Candy provide easy, code-free options for working with PDF files. For those interested in trying [IronPDF](trial license), making it an excellent option for developers to test out its HTML-to-PDF conversion and PDF manipulation features before committing to a paid license. The trial allows you to explore its premium features, such as high-quality PDF file generation, security options, and modifying existing PDF documents, giving you hands-on experience with the tool’s capabilities. If your project requires frequent HTML-to-PDF conversions or complex PDF editing, IronPDF's free trial is a great way to see if it fits your needs. By evaluating the specific features of each tool and your project’s scope, you can choose the best solution for generating PDF files efficiently in C#. 常見問題解答 如何在C#中將HTML轉換為PDF? 您可以使用 IronPDF 的RenderHtmlAsPdf方法將 HTML 字串轉換為 PDF。您也可以使用RenderHtmlFileAsPdf將 HTML 檔案轉換為 PDF。 免費和付費的 C# PDF 庫有什麼區別? 像 PDFsharp 這樣的免費庫非常適合基本的 PDF 創建和操作,而像 IronPDF 這樣的付費庫則提供 HTML 轉 PDF、表單處理和增強安全性等高級功能。 在 C# 中,用於基本 PDF 處理的最佳開源程式庫是什麼? PDFsharp 是一個輕量級的開源 .NET PDF 函式庫,非常適合基本的 PDF 建立任務。它可免費用於商業和非商業用途。 iTextSharp 如何支援安全建立 PDF 文件? iTextSharp 提供豐富的自訂選項,用於建立安全的 PDF 文檔,包括支援數位簽章和加密,使其適用於需要安全文件處理的行業。 我可以在 C# 應用程式中使用線上工具將 HTML 轉換為 PDF 嗎? 是的,像 PDFShift 和 DocRaptor 這樣的線上工具提供了基於 API 的 HTML 到 PDF 轉換功能,這對於需要動態產生 PDF 的 Web 應用程式來說是理想的選擇。 使用基於 Chromium 的渲染引擎的庫來產生 PDF 有哪些優勢? IronPDF 等庫使用基於 Chromium 的渲染引擎,提供高品質的 HTML 到 PDF 轉換,並支援複雜的樣式和 JavaScript。 Syncfusion PDF Library 如何讓企業應用程式受益? Syncfusion PDF 庫為企業應用程式提供全面的功能,包括表單處理、數位簽章和加密,使其非常適合複雜的專業需求。 IronPDF 是否相容於即將發布的 .NET 10 版本? 是的-IronPDF 開箱即用,支援 .NET 10。它與 .NET 9、8、7、6、Core、Standard 和 Framework 版本一樣,都被列為 .NET 10 的相容版本,無需任何特殊設定。 (ironpdf.com) Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多 發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多 發表日期 11月 13, 2025 如何建立 .NET HTML 轉 PDF 轉換器 學習如何在.NET中使用IronPDF將HTML轉換為PDF。 閱讀更多 如何在C#中不使用庫將HTML轉換為PDFhtml2pdf中的C#頁面中斷修訂...
發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多
發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多