產品比較 IronPDF與Apitron PDF Kit的比較 Curtis Chau 更新:2026年1月20日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 T在C#中處理PDF文件對開發人員來說可能具有挑戰性。 創建這些文件的內容時需要考慮許多因素,而將不同格式的內容轉換為PDF時需要考慮更多因素。 自動化現在在軟體開發過程中至關重要。 這些挑戰已經通過開發旨在幫助閱讀、寫入、創建和修改PDF文檔,以及編輯其屬性並將其從其他格式轉換的庫來解決。 這篇博客文章比較了用於.NET和.NET Core的兩個PDF庫: IronPDF程式庫 Apitron PDF Kit IronPDF和Apitron PDF Kit是提供.NET和.NET Core PDF操作功能的程式庫。 他們都可以用於文件字段轉換和操縱任務。 它們還允許創建書籤。 下一步是決定哪個C# PDF .NET程式庫最適合我們的.NET專案。 這篇比較文章將幫助您在這兩個PDF程式庫之間做出選擇。 首先,讓我們探索這兩個程式庫提供的功能,然後進入比較本身。 Apitron PDF Kit Library及其功能 Apitron PDF Kit是允許您以多種方式操縱或轉換PDF文件的.NET組件。 您可以添加圖片、圖畫和文字,簽署文件,以及更多。 您還可以編輯現有內容。 Apitron PDF Kit .NET組件可用於創建多平台的移動、桌面、網路、Windows和雲應用程式。 使用此PDF SDK,您將能夠: 提取、修改和添加圖形(文字、圖片、圖畫) 拆分或合併PDF文件 填寫或創建受密碼保護的PDF表單,支持FDF 創建具有可選內容組(OCG)的多層PDF文檔 添加或移除文檔中的字段 使用從右到左的文字或雙向文字創建頁面內容 檢查文件中的資源——字體定義、嵌入文件 對PDF文件進行數字簽名並檢查現有簽名 IronPDF的主要功能 開發人員,特別是C#程序員,將欣賞IronPDF .NET程式庫。 使用此工具,您可以輕鬆構建.NET Core PDF處理應用程式。 IronPDF使用.NET Chromium引擎將HTML頁面(以代碼或URL形式)轉換為PDF文件。 無需使用復雜的API來定位導航物件或從HTML設計PDF。 IronPDF支援標準網頁文件,包括HTML、ASPX、JS、CSS和圖片。 IronPDF可以使用HTML5、CSS、JS和圖片創建。 PDF可以輕鬆編輯、加蓋和添加頁眉和頁腳。 它也使閱讀PDF文字和提取圖形變得簡單。 IronPDF的亮點功能包括: 使用HTML4/5、CSS和JavaScript創建PDF文件 使用自定義網路登錄憑據、用戶代理、代理、cookies、HTTP頭和表單變數加載URL(允許在HTML登錄表單後面登錄) 閱讀和填寫PDF表單字段 從PDF中提取文本和圖形 使用新的HTML內容更新PDF頁面 創建基於文本或HTML的頁眉和頁腳 合併和分離PDF文檔內容 將ASP.NET Web表單轉換為可打印的PDF 在沒有Adobe Acrobat軟體的情況下打印PDF文件 IronPDF幾乎在所有與C#兼容的操作系統和框架上均可用,包括: .NET Core 2.1, 3.0, 3.1, .NET 6 & 5 適用於通用兼容性的.NET Standard 2.0合規 Azure、AWS、Docker、Linux、Windows 文章的其餘部分如下: IronPDF安裝 Apitron PDF Kit安裝 創建PDF文件 創建PDF中的頁眉和頁腳 PDF數字簽名 價格和授權 1. IronPDF安裝 有四種方法可以下載和安裝IronPDF程式庫。 這些方法是: 使用NuGet套件管理器 使用開發者命令提示符 直接下載NuGet套件 下載IronPDF .DLL程式庫 1.1. 使用NuGet套件管理器 要安裝IronPDF,只需在解決方案資源管理器中右鍵單擊您的項目。 這將打開NuGet套件管理器。 使用解決方案資源管理器訪問NuGet套件管理器 選擇後,瀏覽IronPDF套件並安裝,如下面的截圖所示。 使用NuGet套件管理器安裝IronPDF程式庫 1.2. 使用開發者命令提示符 您也可以通過開發者命令提示符安裝IronPDF。 打開開發者命令提示符(通常在Visual Studio文件夾中) 輸入以下命令: Install-Package IronPdf 按Enter鍵 這將下載並安裝套件 重新加載您的項目並開始使用 1.3. 直接下載NuGet套件 您也可以通過直接訪問IronPDF NuGet套件網站並下載套件來安裝IronPDF。 步驟如下: 瀏覽至IronPDF NuGet套件 選擇下載套件 雙擊下載的套件 套件將被安裝 重新加載您的Visual Studio項目並開始使用 IronPDF已下載並可使用。 然而,在此之前,我們應該安裝Apitron PDF程式庫。 2. Apitron PDF Kit安裝 對於.NET Core應用程式,我們可以使用NuGet套件管理器安裝Apitron,或者直接從Apitron PDF Kit NuGet網站下載並安裝Apitron。 如同IronPDF中一樣,在Visual Studio中開啟NuGet套件。 搜索Apitron.PDF.Kit。 在當前項目中單擊安裝。 Apitron PDF Kit搜尋 您也可以使用NuGet套件管理器控制台來安裝Apitron。 按照IronPDF中提到的"使用開發者命令提示符"步驟並輸入以下命令: Install-Package Apitron.PDF.Kit 按下ENTER鍵。 這將下載並安裝Apitron.PDF.Kit。 添加以下命名空間: using Apitron.PDF.Kit; using Apitron.PDF.Kit.FixedLayout.Resources; using Apitron.PDF.Kit.FixedLayout.Resources.Fonts; using Apitron.PDF.Kit.FlowLayout.Content; using Apitron.PDF.Kit.Styles; using Apitron.PDF.Kit.Styles.Appearance; using Font = Apitron.PDF.Kit.Styles.Text.Font; using Apitron.PDF.Kit; using Apitron.PDF.Kit.FixedLayout.Resources; using Apitron.PDF.Kit.FixedLayout.Resources.Fonts; using Apitron.PDF.Kit.FlowLayout.Content; using Apitron.PDF.Kit.Styles; using Apitron.PDF.Kit.Styles.Appearance; using Font = Apitron.PDF.Kit.Styles.Text.Font; $vbLabelText $csharpLabel 現在,讓我們進入IronPDF和Apitron PDF的比較。 3. 創建PDF文件 3.1. 使用IronPDF IronPDF有多種方法來創建PDF。 讓我們探索兩個重要的方法。 現有URL到PDF IronPDF使得將任何URL轉換為PDF變得容易。 以下代碼幫助將URL轉換為PDF。 var Renderer = new IronPdf.ChromePdfRenderer(); // Render a PDF from an existing URL using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/"); // Save the PDF to a file Pdf.SaveAs("url.pdf"); var Renderer = new IronPdf.ChromePdfRenderer(); // Render a PDF from an existing URL using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/"); // Save the PDF to a file Pdf.SaveAs("url.pdf"); $vbLabelText $csharpLabel HTML輸入字符串到PDF 下面的代碼解釋了如何從HTML字符串渲染PDF文件。 您可以僅使用HTML,或將其與CSS、圖片和JavaScript組合使用。 var Renderer = new IronPdf.ChromePdfRenderer(); // Render a PDF from a simple HTML string using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>"); PDF.SaveAs("pixel-perfect.pdf"); // Load external HTML assets like images, CSS, and JavaScript // Set the optional BasePath as the file location to load assets from using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\"); AdvancedPDF.SaveAs("html-with-assets.pdf"); var Renderer = new IronPdf.ChromePdfRenderer(); // Render a PDF from a simple HTML string using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>"); PDF.SaveAs("pixel-perfect.pdf"); // Load external HTML assets like images, CSS, and JavaScript // Set the optional BasePath as the file location to load assets from using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\"); AdvancedPDF.SaveAs("html-with-assets.pdf"); $vbLabelText $csharpLabel 輸出如下: IronPDF從URL和HTML CSS字符串生成PDF 3.2. 使用Apitron PDF Kit Apitron PDF沒有提供將URL或HTML轉換為PDF的方法。 它允許將PDF轉換為HTML。 但是,它也可以將XML文件轉換為PDF。 使用的XML文件是: <?xml version="1.0" encoding="utf-8"?> <FlowDocument xmlns="Apitron.PDF.Kit.FlowLayout.v1"> <Resources> <Image resourceId="logo" fileName="../../images/logo.png" /> </Resources> <Styles> <Style selector="flowdocument"> <Color value="Black" /> </Style> <Style selector="grid"> <InnerBorder thickness="1" /> <InnerBorderColor value="Black" /> </Style> </Styles> <Elements> <Image> <Properties> <Class value="logo" /> <ResourceId value="logo" /> </Properties> </Image> <TextBlock> <Properties> <Class value="header" /> <Text value="Sample Interview Questions for Candidates" /> </Properties> </TextBlock> <Br /> <TextBlock> <Properties> <Class value="headerNote" /> <Text value="To help facilitate the interview process, the Human Resources Department has compiled a list of questions that might be used during the phone and/or on-campus interviews. Some of the questions deal with the same content, but are phrased differently while other questions may not pertain to a specific discipline; however all of the questions are unbiased and appropriate to ask. We hope you'll find this helpful." /> </Properties> </TextBlock> </Elements> <Properties> <Margin value="30,20,30,20" /> </Properties> </FlowDocument> <?xml version="1.0" encoding="utf-8"?> <FlowDocument xmlns="Apitron.PDF.Kit.FlowLayout.v1"> <Resources> <Image resourceId="logo" fileName="../../images/logo.png" /> </Resources> <Styles> <Style selector="flowdocument"> <Color value="Black" /> </Style> <Style selector="grid"> <InnerBorder thickness="1" /> <InnerBorderColor value="Black" /> </Style> </Styles> <Elements> <Image> <Properties> <Class value="logo" /> <ResourceId value="logo" /> </Properties> </Image> <TextBlock> <Properties> <Class value="header" /> <Text value="Sample Interview Questions for Candidates" /> </Properties> </TextBlock> <Br /> <TextBlock> <Properties> <Class value="headerNote" /> <Text value="To help facilitate the interview process, the Human Resources Department has compiled a list of questions that might be used during the phone and/or on-campus interviews. Some of the questions deal with the same content, but are phrased differently while other questions may not pertain to a specific discipline; however all of the questions are unbiased and appropriate to ask. We hope you'll find this helpful." /> </Properties> </TextBlock> </Elements> <Properties> <Margin value="30,20,30,20" /> </Properties> </FlowDocument> XML 將這個XML模板轉換為PDF的代碼如下: // Use Apitron's FlowDocument to convert XML to PDF using (Stream stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"), outputStream = File.Create("fromTemplate.pdf")) { ResourceManager resourceManager = new ResourceManager(); FlowDocument doc = FlowDocument.LoadFromXml(stream, resourceManager); doc.Write(outputStream, resourceManager); } // Use Apitron's FlowDocument to convert XML to PDF using (Stream stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"), outputStream = File.Create("fromTemplate.pdf")) { ResourceManager resourceManager = new ResourceManager(); FlowDocument doc = FlowDocument.LoadFromXml(stream, resourceManager); doc.Write(outputStream, resourceManager); } $vbLabelText $csharpLabel 輸出如下: Apitron PDF文件 如果我們比較IronPDF和Apitron的輸出,我們可以清楚地看到IronPDF通過HTML渲染和不縮放圖像尺寸創建令人印象深刻的文件。而Apitron給出的輸出與IronPDF相似,但只有當XML文件有註冊樣式時。 4. 添加頁眉和頁腳到PDF文檔 4.1. 使用IronPDF 使用IronPDF添加頁眉和頁腳非常簡單。 IronPDF允許您添加頁碼和分頁符、附加封面頁、邊距等。 添加頁眉和頁腳的代碼如下: var Renderer = new ChromePdfRenderer(); // Add a header Renderer.RenderingOptions.FirstPageNumber = 1; // Use 2 if a cover page will be appended Renderer.RenderingOptions.TextHeader.DrawDividerLine = true; Renderer.RenderingOptions.TextHeader.CenterText = "This is the header text"; Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica; Renderer.RenderingOptions.TextHeader.FontSize = 12; Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for header // Add a footer too Renderer.RenderingOptions.TextFooter.DrawDividerLine = true; Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial; Renderer.RenderingOptions.TextFooter.FontSize = 12; Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"; Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"; Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for footer using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>This is header and footer generated pdf file</h1>", @"C:\site\assets\"); AdvancedPDF.SaveAs("html-with-assets.pdf"); var Renderer = new ChromePdfRenderer(); // Add a header Renderer.RenderingOptions.FirstPageNumber = 1; // Use 2 if a cover page will be appended Renderer.RenderingOptions.TextHeader.DrawDividerLine = true; Renderer.RenderingOptions.TextHeader.CenterText = "This is the header text"; Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica; Renderer.RenderingOptions.TextHeader.FontSize = 12; Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for header // Add a footer too Renderer.RenderingOptions.TextFooter.DrawDividerLine = true; Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial; Renderer.RenderingOptions.TextFooter.FontSize = 12; Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"; Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"; Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for footer using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>This is header and footer generated pdf file</h1>", @"C:\site\assets\"); AdvancedPDF.SaveAs("html-with-assets.pdf"); $vbLabelText $csharpLabel 輸出如下: IronPDF頁眉和頁腳 4.2. 使用Apitron PDF Kit Apitron PDF Kit通過將XML結構格式中的內容轉換為PDF來創建PDF。 在Apitron PDF Kit中,可以使用PageFooter屬性添加頁眉和頁腳。 這樣做的代碼如下: // Register document resources first ResourceManager resourceManager = new ResourceManager(); resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", "../../data/logo.png")); // Create the document FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) }; // Register styles doc.StyleManager.RegisterStyle(".pageHeader", new Style() { Font = new Font(StandardFonts.TimesBold, 20) }); doc.StyleManager.RegisterStyle(".pageFooter", new Style() { Align = Align.Right }); doc.StyleManager.RegisterStyle("hr", new Style() { Height = 2, Margin = new Thickness(0, 5, 0, 5) }); doc.StyleManager.RegisterStyle(".content", new Style() { Align = Align.Left, Display = Display.InlineBlock }); // Fill the header section doc.PageHeader.Class = "pageHeader"; doc.PageHeader.Add(new Image("logo") { Width = 100, Height = 50 }); doc.PageHeader.Add(new TextBlock("This document is intended for internal use only") { TextIndent = 20 }); doc.PageHeader.Add(new Hr()); // Fill the footer section doc.PageFooter.Class = "pageFooter"; doc.PageFooter.Add(new Hr()); doc.PageFooter.Add(new TextBlock((ctx) => string.Format("Page {0} from ", ctx.CurrentPage + 1))); doc.PageFooter.Add(new PageCount(3) { Display = Display.Inline }); // Add pages for (int i = 0; i < 2; ++i) { doc.Add(new TextBlock("This is header and footer generation pdf file.") { Class = "content" }); doc.Add(new PageBreak()); } // Generate PDF using (Stream stream = File.Create("out.pdf")) { doc.Write(stream, resourceManager); } Process.Start("out.pdf"); // Register document resources first ResourceManager resourceManager = new ResourceManager(); resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", "../../data/logo.png")); // Create the document FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) }; // Register styles doc.StyleManager.RegisterStyle(".pageHeader", new Style() { Font = new Font(StandardFonts.TimesBold, 20) }); doc.StyleManager.RegisterStyle(".pageFooter", new Style() { Align = Align.Right }); doc.StyleManager.RegisterStyle("hr", new Style() { Height = 2, Margin = new Thickness(0, 5, 0, 5) }); doc.StyleManager.RegisterStyle(".content", new Style() { Align = Align.Left, Display = Display.InlineBlock }); // Fill the header section doc.PageHeader.Class = "pageHeader"; doc.PageHeader.Add(new Image("logo") { Width = 100, Height = 50 }); doc.PageHeader.Add(new TextBlock("This document is intended for internal use only") { TextIndent = 20 }); doc.PageHeader.Add(new Hr()); // Fill the footer section doc.PageFooter.Class = "pageFooter"; doc.PageFooter.Add(new Hr()); doc.PageFooter.Add(new TextBlock((ctx) => string.Format("Page {0} from ", ctx.CurrentPage + 1))); doc.PageFooter.Add(new PageCount(3) { Display = Display.Inline }); // Add pages for (int i = 0; i < 2; ++i) { doc.Add(new TextBlock("This is header and footer generation pdf file.") { Class = "content" }); doc.Add(new PageBreak()); } // Generate PDF using (Stream stream = File.Create("out.pdf")) { doc.Write(stream, resourceManager); } Process.Start("out.pdf"); $vbLabelText $csharpLabel 輸出如下: Apitron頁眉和頁腳 5. PDF數字簽名 5.1. 使用IronPDF PDF處理功能中最重要的一個功能是能夠數位簽署PDF文件。 IronPDF提供了完成此操作所需的所有工具。 using IronPdf; // Cryptographically sign an existing PDF in 1 line of code! new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf"); /***** Advanced example for more control *****/ // 1. Create a PDF var Renderer = new IronPdf.ChromePdfRenderer(); var doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>"); // 2. Create a Signature. // You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader. var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456"); // 3. Handwritten signature graphic signature.LoadSignatureImageFromFile("handwriting.png"); // 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used doc.SignPdfWithDigitalSignature(signature); // 5. The PDF is not signed until saved to file, stream or byte array. doc.SaveAs("signed.pdf"); using IronPdf; // Cryptographically sign an existing PDF in 1 line of code! new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf"); /***** Advanced example for more control *****/ // 1. Create a PDF var Renderer = new IronPdf.ChromePdfRenderer(); var doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>"); // 2. Create a Signature. // You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader. var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456"); // 3. Handwritten signature graphic signature.LoadSignatureImageFromFile("handwriting.png"); // 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used doc.SignPdfWithDigitalSignature(signature); // 5. The PDF is not signed until saved to file, stream or byte array. doc.SaveAs("signed.pdf"); $vbLabelText $csharpLabel 5.2 使用Apitron PDF Kit 使用Apitron PDF Kit為PDF加蓋簽名是一個冗長且技術性過程。 static void Main(string[] args) { string fileName = "signedTwice.pdf"; using (Stream stream = File.Create(fileName)) { FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) }; doc.Add(new TextBlock("Signed using Apitron PDF Kit for .NET")); doc.Write(stream, new ResourceManager()); } // Save Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", new Boundary(10, 750, 110, 800)); } // Implementation of Sign Method private static void Sign(string pathToDocument, string pathToCertificate, string password, string pathToSignatureImage, Boundary signatureViewLocation) { // Open existing document and sign once using (Stream inputStream = new FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite)) { using (FixedDocument doc = new FixedDocument(inputStream)) { string imageResourceId = Guid.NewGuid().ToString("N"); string signatureFieldId = Guid.NewGuid().ToString("N"); // Register signature image resource doc.ResourceManager.RegisterResource(new Image(imageResourceId, pathToSignatureImage)); // Create first signature field and initialize it using a stored certificate SignatureField signatureField = new SignatureField(signatureFieldId); using (Stream signatureDataStream = File.OpenRead(pathToCertificate)) { signatureField.Signature = Signature.Create(new Pkcs12Store(signatureDataStream, password)); } // Add signature fields to the document doc.AcroForm.Fields.Add(signatureField); // Create first signature view using the image resource SignatureFieldView signatureView = new SignatureFieldView(signatureField, signatureViewLocation); signatureView.ViewSettings.Graphic = Graphic.Image; signatureView.ViewSettings.GraphicResourceID = imageResourceId; signatureView.ViewSettings.Description = Description.None; // Add views to page annotations collection doc.Pages[0].Annotations.Add(signatureView); // Save as incremental update doc.Save(); } } } static void Main(string[] args) { string fileName = "signedTwice.pdf"; using (Stream stream = File.Create(fileName)) { FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) }; doc.Add(new TextBlock("Signed using Apitron PDF Kit for .NET")); doc.Write(stream, new ResourceManager()); } // Save Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", new Boundary(10, 750, 110, 800)); } // Implementation of Sign Method private static void Sign(string pathToDocument, string pathToCertificate, string password, string pathToSignatureImage, Boundary signatureViewLocation) { // Open existing document and sign once using (Stream inputStream = new FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite)) { using (FixedDocument doc = new FixedDocument(inputStream)) { string imageResourceId = Guid.NewGuid().ToString("N"); string signatureFieldId = Guid.NewGuid().ToString("N"); // Register signature image resource doc.ResourceManager.RegisterResource(new Image(imageResourceId, pathToSignatureImage)); // Create first signature field and initialize it using a stored certificate SignatureField signatureField = new SignatureField(signatureFieldId); using (Stream signatureDataStream = File.OpenRead(pathToCertificate)) { signatureField.Signature = Signature.Create(new Pkcs12Store(signatureDataStream, password)); } // Add signature fields to the document doc.AcroForm.Fields.Add(signatureField); // Create first signature view using the image resource SignatureFieldView signatureView = new SignatureFieldView(signatureField, signatureViewLocation); signatureView.ViewSettings.Graphic = Graphic.Image; signatureView.ViewSettings.GraphicResourceID = imageResourceId; signatureView.ViewSettings.Description = Description.None; // Add views to page annotations collection doc.Pages[0].Annotations.Add(signatureView); // Save as incremental update doc.Save(); } } } $vbLabelText $csharpLabel 對於這些程式庫來說,輸出幾乎是一樣的。 您可以清楚地看到,IronPDF在操縱PDF內容方面更簡單和方便。 輸出PDF已經簽名,並在其上打印了證書和簽名。 使用Bootstrap 5與IronPDF進行作品集庫 IronPDF的Chrome V8渲染引擎完全支持現代Bootstrap 5組件,使您能夠生成視覺驚人的PDF文件和專業作品集庫。 此示例演示了網格佈局、懸停效果、漸變疊加和類別徽章——這些功能用傳統的Apitron PDF SDK庫難以實現。 using IronPdf; var renderer = new ChromePdfRenderer(); string portfolioGallery = @" <!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> .gallery-item { position: relative; overflow: hidden; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .gallery-item img { width: 100%; height: 250px; object-fit: cover; transition: transform 0.3s; } .gallery-item:hover img { transform: scale(1.1); } .gallery-overlay { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 20px; color: white; } .category-badge { position: absolute; top: 10px; right: 10px; } @media print { .gallery-item { page-break-inside: avoid; } } </style> </head> <body> <div class='container py-5'> <div class='text-center mb-5'> <h1 class='display-4'>Design Portfolio</h1> <p class='lead text-muted'>Showcase of PDF Document Designs</p> </div> <div class='row mb-4'> <div class='col-12'> <div class='btn-group' role='group'> <button class='btn btn-primary'>All Projects</button> <button class='btn btn-outline-primary'>Invoices</button> <button class='btn btn-outline-primary'>Reports</button> <button class='btn btn-outline-primary'>Forms</button> <button class='btn btn-outline-primary'>Certificates</button> </div> </div> </div> <div class='row g-4'> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-primary category-badge'>Invoice</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📄</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Professional Invoice Template</h5> <small>Corporate billing with itemized details</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-success category-badge'>Report</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📊</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Analytics Dashboard Report</h5> <small>Data visualization and metrics</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-warning category-badge'>Certificate</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>🏆</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Award Certificate</h5> <small>Professional achievement recognition</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-info category-badge'>Form</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #fa709a 0%, #fee140 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📝</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Application Form</h5> <small>Multi-page data collection</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-danger category-badge'>Invoice</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #30cfd0 0%, #330867 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>💰</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Payment Receipt</h5> <small>Transaction confirmation document</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-secondary category-badge'>Report</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📈</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Financial Statement</h5> <small>Quarterly performance overview</small> </div> </div> </div> </div> <div class='text-center mt-5'> <p class='text-muted'>All templates rendered with IronPDF's Chromium engine</p> <div class='d-flex justify-content-center gap-2'> <span class='badge bg-primary'>Bootstrap 5</span> <span class='badge bg-success'>Responsive</span> <span class='badge bg-info'>Print-Ready</span> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(portfolioGallery); pdf.SaveAs("portfolio-gallery.pdf"); using IronPdf; var renderer = new ChromePdfRenderer(); string portfolioGallery = @" <!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> .gallery-item { position: relative; overflow: hidden; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .gallery-item img { width: 100%; height: 250px; object-fit: cover; transition: transform 0.3s; } .gallery-item:hover img { transform: scale(1.1); } .gallery-overlay { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 20px; color: white; } .category-badge { position: absolute; top: 10px; right: 10px; } @media print { .gallery-item { page-break-inside: avoid; } } </style> </head> <body> <div class='container py-5'> <div class='text-center mb-5'> <h1 class='display-4'>Design Portfolio</h1> <p class='lead text-muted'>Showcase of PDF Document Designs</p> </div> <div class='row mb-4'> <div class='col-12'> <div class='btn-group' role='group'> <button class='btn btn-primary'>All Projects</button> <button class='btn btn-outline-primary'>Invoices</button> <button class='btn btn-outline-primary'>Reports</button> <button class='btn btn-outline-primary'>Forms</button> <button class='btn btn-outline-primary'>Certificates</button> </div> </div> </div> <div class='row g-4'> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-primary category-badge'>Invoice</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📄</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Professional Invoice Template</h5> <small>Corporate billing with itemized details</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-success category-badge'>Report</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📊</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Analytics Dashboard Report</h5> <small>Data visualization and metrics</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-warning category-badge'>Certificate</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>🏆</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Award Certificate</h5> <small>Professional achievement recognition</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-info category-badge'>Form</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #fa709a 0%, #fee140 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📝</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Application Form</h5> <small>Multi-page data collection</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-danger category-badge'>Invoice</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #30cfd0 0%, #330867 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>💰</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Payment Receipt</h5> <small>Transaction confirmation document</small> </div> </div> </div> <div class='col-md-4'> <div class='gallery-item'> <span class='badge bg-secondary category-badge'>Report</span> <svg width='100%' height='250' style='background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'> <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📈</text> </svg> <div class='gallery-overlay'> <h5 class='mb-1'>Financial Statement</h5> <small>Quarterly performance overview</small> </div> </div> </div> </div> <div class='text-center mt-5'> <p class='text-muted'>All templates rendered with IronPDF's Chromium engine</p> <div class='d-flex justify-content-center gap-2'> <span class='badge bg-primary'>Bootstrap 5</span> <span class='badge bg-success'>Responsive</span> <span class='badge bg-info'>Print-Ready</span> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(portfolioGallery); pdf.SaveAs("portfolio-gallery.pdf"); $vbLabelText $csharpLabel 此代碼生成具有響應式網格佈局、視覺類別徽章、漸變疊加和懸停效果的專業PDF作品集。 Chrome渲染引擎保留了所有Bootstrap樣式、CSS網格佈局和自定義CSS屬性——這是傳統PDF庫難以複製的功能。 與Apitron PDF SDK的主要優勢: 原生Bootstrap 5支持,無需轉換 CSS網格和Flexbox佈局完美呈現 漸變背景和現代CSS效果 簡單代碼加上更高質量的輸出 有關Bootstrap PDF生成的完整指南,請參見HTML到PDF Bootstrap指南。 6. 價格和授權 IronPDF的定價與授權 IronPDF是一個免費使用於開發的C#程式庫,可隨時授權用於商業用途。專案授權可用於單一開發人員、機構和跨國組織,以及SaaS和OEM再分發。 所有授權均提供30天退款保證,一年支援和升級,開發/階段/生產有效性,以及永久授權(一次購買)。 Lite方案僅需$799,無持續費用。 有關選擇最佳授權的詳細信息和幫助,可在IronPDF產品授權頁面找到。 IronPDF授權 Apitron PDF Kit價格和授權 目前有兩種授權方案——現代和傳統。 如果您已經有授權,那麼傳統授權方案在您的授權失效之前仍然有效。 之後,您需要聯繫客戶支援進行轉換。 現代授權方案僅適用於新客戶。 在現代方案下,有三個授權層級: Evaluation - 三個月的評估期,可以使用完整功能的產品。 只需從NuGet下載套件並開始開發。 Community - 在非商業專案中免費使用完整功能的產品。 需要批准。 Commercial - 上述未描述的任何使用情形。 定價依照使用模式決定。 結論 IronPDF程式庫從HTML、JS、CSS、JPG、PNG、GIF和SVG等文件類型創建出像素完美的PDF。 Chromium引擎幫助渲染HTML文件或URL,生成完美的PDF。 Apitron允許您使用Fixed Layout API創建PDF,這種API是為了與PDF規範100%兼容而實施的。 作為一種類似於HTML和CSS的樣式驅動內容生成方法,這種固定佈局API允許您在幾分鐘內創建令人驚豔的報告、賬單、目錄等。 它還支持創建XML模板。 Apitron PDF的授權價格在其網站上沒有提供。您需要聯繫支援並根據您的使用情況獲取報價。 另一方面,IronPDF在其網站上清楚地顯示了授權方案。這使IronPDF在競爭對手中脫穎而出,並允許用戶根據自己的需求明智地選擇。 使用IronPDF,您可以比使用Apitron PDF更輕鬆地處理PDF文件。 IronPDF允許用戶為挑戰性的PDF工作編寫更少的代碼。 IronPDF提供多種方法從多種文件類型生成PDF,而Apitron只能將XML文件轉換為PDF文件。 在IronPDF中實現的完美輸出無需添加任何技術選項,與Apitron相比。 所有Iron Software客戶都有選擇以兩個產品的價格購買公司全部五個產品的選項。 試用IronPDF免費30天試用以測試其完整功能。 購買Iron Software產品的完整套件。 請注意Apitron PDF Kit 是其相關所有者的註冊商標。 此網站與Apitron PDF Kit無關,未獲得其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,並反映了撰寫本文時的公開信息。)}] 常見問題解答 如何在 C# 中將 HTML 轉換為 PDF? 您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字符串轉換為 PDF。您還可以使用 RenderHtmlFileAsPdf 將 HTML 文件轉換為 PDF。 IronPDF 為 PDF 創建提供什麼功能? IronPDF 支援從 HTML、CSS 和 JavaScript 創建 PDF,載入 URL,提取文本和圖形,合併 PDF 等。它與 .NET Core、Azure、AWS、Docker、Linux 和 Windows 兼容。 如何在 C# 中以數位方式簽署 PDF? 使用 IronPDF,您可以使用 PDF 簽名證書來以數位方式簽署 PDF,只需幾行代碼即可集成。 IronPDF 的安裝選項有哪些? IronPDF 可使用 NuGet 套件管理器、開發者命令提示符安裝,或直接下載 NuGet 套件或 IronPDF .DLL 庫進行安裝。 IronPDF 是否有免費版本? 是的,IronPDF 提供免費的開發版本以及商業許可證。詳細的定價資訊,包括 30 天退款保證,可在其網站上查詢。 Apitron PDF Kit 怎麼進行 HTML 到 PDF 的轉換? Apitron PDF Kit 不支援直接 HTML 到 PDF 的轉換,但可以將 XML 文件轉換為 PDF。 Apitron PDF Kit 的突出功能有哪些? Apitron PDF Kit 可以全面操作 PDF,包括添加圖像、圖形、文本、簽署文件,合併或拆分 PDF。然而,它缺乏直接的 HTML 到 PDF 轉換功能。 如何在 C# 中向 PDF 添加頁眉和頁腳? IronPDF 使您可以使用 AddTextHeader 和 AddTextFooter 等方法輕鬆地向 PDF 添加頁眉和頁腳。 Apitron PDF Kit 提供哪些許可證選項? Apitron PDF Kit 提供三個月的評估期和非商業專案的社區許可證。對於商業用途,您需要直接聯繫他們以獲取報價。 哪個 PDF 庫對 .NET 開發更容易使用? IronPDF 一般來說更容易用於 .NET 開發,提供更簡單明瞭的 API,並且需要的代碼行數較少,適合於複雜任務,而 Apitron PDF Kit 則較繁瑣。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新2026年3月1日 在 ASP.NET MVC 中生成 PDF:iTextSharp vs IronPDF 指南 比較在 ASP.NET MVC 中使用 iTextSharp vs IronPDF 的 PDF 產生方法。發現哪個函式庫能提供更好的 HTML 呈現以及更容易的實作。 閱讀更多 更新2026年2月1日 Ghostscript GPL vs IronPDF:技術比較指南 探索 Ghostscript GPL 與 IronPDF 的主要差異。比較 AGPL 授權與商業授權、指令列開關與本機 .NET API,以及 HTML-to-PDF 功能。 閱讀更多 更新2026年3月1日 ASP PDF 庫:比較 IronPDF、Aspose 和 Syncfusion 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多 Telerik的HTML到PDF生成器與IronPDFIronPDF vs GroupDocs:工程團隊...
更新2026年3月1日 在 ASP.NET MVC 中生成 PDF:iTextSharp vs IronPDF 指南 比較在 ASP.NET MVC 中使用 iTextSharp vs IronPDF 的 PDF 產生方法。發現哪個函式庫能提供更好的 HTML 呈現以及更容易的實作。 閱讀更多
更新2026年2月1日 Ghostscript GPL vs IronPDF:技術比較指南 探索 Ghostscript GPL 與 IronPDF 的主要差異。比較 AGPL 授權與商業授權、指令列開關與本機 .NET API,以及 HTML-to-PDF 功能。 閱讀更多
更新2026年3月1日 ASP PDF 庫:比較 IronPDF、Aspose 和 Syncfusion 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多