IronPDF與Apitron PDF Kit的比較
對於開發人員而言,在 C# 中處理 PDF 檔案可能是一項挑戰。 在為這些檔案製作內容時需考量許多因素,而將不同格式的內容轉換為 PDF 時,需考量的因素更是眾多。 自動化現已成為軟體開發流程中不可或缺的一環。 為解決這些挑戰,開發了專門用於讀取、寫入、建立及修改 PDF 文件,以及編輯其屬性並將其從其他格式轉換的函式庫。
這篇部落格文章比較了兩款適用於 .NET 和 .NET Core 的 PDF 函式庫:
- IronPDF 函式庫
- Apitron PDF 套件
IronPDF 和 Apitron PDF Kit 是為 .NET 和 .NET Core 提供 PDF 處理功能的函式庫。 這兩種工具都可以用於文件欄位轉換和操作任務。 它們也支援建立書籤。 下一步是決定哪款 C# PDF .NET 函式庫最適合我們的 .NET 專案。 這篇比較文章將協助您在這兩個 PDF 函式庫之間做出決定。
首先,讓我們探討這兩套函式庫的功能,接著再進行比較。
Apitron PDF 套件庫及其功能
Apitron PDF Kit 是一款 .NET 元件,可讓您以多種方式操作或轉換 PDF 檔案。 您可以添加圖片、圖形和文字、簽署文件,以及執行更多操作。 您也可以編輯現有內容。 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 網頁表格轉換為可列印的 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
文章的其他部分如下:
1.安裝 IronPDF 2.Apitron PDF 套件安裝 3.建立 PDF 文件 4.在 PDF 中建立頁首與頁尾 5.數位簽署 PDF 6.定價與授權
1.IronPDF 安裝
有四種方法可以下載並安裝 IronPDF 函式庫。 這些工具包括
1.使用 NuGet 套件管理員 2.開發人員指令提示 3.直接下載 NuGet 套件 4.下載 IronPDF .DLL 函式庫
1.1.使用 NuGet 套件管理員
要安裝 IronPDF,只需在 Solution Explorer 中的專案上按一下滑鼠右鍵。 這將會開啟 NuGet Package Manager。
使用"解決方案總管"存取 NuGet 套件管理員
選定後,瀏覽 IronPDF 套件並進行安裝,如下截圖所示。
使用 NuGet 套件管理器安裝 IronPDF 函式庫
1.2.使用開發人員指令提示
您也可以透過 Developer Command Prompt 安裝 IronPDF。
- 開啟 Developer Command Prompt -- 通常可在 Visual Studio 資料夾下找到
- 鍵入以下指令:
Install-Package IronPdf
- 按 Enter
- 這將會下載並安裝套件
- 重新載入您的專案並開始使用
1.3.直接下載 NuGet 套件
IronPDF 也可以透過直接造訪 IronPDF NuGet Package 網站並下載套件來安裝。 步驟如下
- 導覽至 IronPDF NuGet 套件。
- 選擇下載套件
- 雙擊下載的套件
- 套件將安裝
- 重新載入您的 Visual Studio 專案並開始使用
IronPDF 下載完成後即可使用。 不過,在此之前,我們應該先安裝 Apitron PDF 函式庫。
2. Apitron PDF 套件安裝
對於 .NET Core 應用程式,我們可以使用 NuGet Package Manager 安裝 Apitron,也可以直接從 Apitron PDF Kit NuGet 網站下載並安裝 Apitron。
- 在 Visual Studio 中打開 NuGet 套件,就像我們在 IronPDF 中做的一樣。
- 搜尋 Apitron.PDF.Kit。
- 在您目前的專案中按一下安裝。
Apitron PDF 套件搜尋
您也可以使用 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;
Imports Apitron.PDF.Kit
Imports Apitron.PDF.Kit.FixedLayout.Resources
Imports Apitron.PDF.Kit.FixedLayout.Resources.Fonts
Imports Apitron.PDF.Kit.FlowLayout.Content
Imports Apitron.PDF.Kit.Styles
Imports Apitron.PDF.Kit.Styles.Appearance
Imports Font = Apitron.PDF.Kit.Styles.Text.Font
現在,讓我們進入 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");
Dim Renderer = New IronPdf.ChromePdfRenderer()
' Render a PDF from an existing URL
Dim Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Save the PDF to a file
Pdf.SaveAs("url.pdf")
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");
Dim Renderer = New IronPdf.ChromePdfRenderer()
' Render a PDF from a simple HTML string
Dim 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
Dim AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", "C:\site\assets\")
AdvancedPDF.SaveAs("html-with-assets.pdf")
輸出內容如下:
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 模板轉換為 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);
}
' Use Apitron's FlowDocument to convert XML to PDF
Using stream As Stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"),
outputStream As Stream = File.Create("fromTemplate.pdf")
Dim resourceManager As New ResourceManager()
Dim doc As FlowDocument = FlowDocument.LoadFromXml(stream, resourceManager)
doc.Write(outputStream, resourceManager)
End Using
輸出內容如下:
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");
Dim 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
Dim 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")
輸出內容如下:
IronPDF 標題與頁尾
4.2.使用 Apitron PDF Kit
Apitron PDF Kit 透過將 XML 結構格式的內容轉換成 PDF 來建立 PDF。 在 Apitron PDF Kit 中,可以使用 PageHeader 和 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");
' Register document resources first
Dim resourceManager As New ResourceManager()
resourceManager.RegisterResource(New Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", "../../data/logo.png"))
' Create the document
Dim doc As New FlowDocument() With {.Margin = New Thickness(10)}
' Register styles
doc.StyleManager.RegisterStyle(".pageHeader", New Style() With {.Font = New Font(StandardFonts.TimesBold, 20)})
doc.StyleManager.RegisterStyle(".pageFooter", New Style() With {.Align = Align.Right})
doc.StyleManager.RegisterStyle("hr", New Style() With {
.Height = 2,
.Margin = New Thickness(0, 5, 0, 5)
})
doc.StyleManager.RegisterStyle(".content", New Style() With {
.Align = Align.Left,
.Display = Display.InlineBlock
})
' Fill the header section
doc.PageHeader.Class = "pageHeader"
doc.PageHeader.Add(New Image("logo") With {
.Width = 100,
.Height = 50
})
doc.PageHeader.Add(New TextBlock("This document is intended for internal use only") With {.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(Function(ctx) String.Format("Page {0} from ", ctx.CurrentPage + 1)))
doc.PageFooter.Add(New PageCount(3) With {.Display = Display.Inline})
' Add pages
For i As Integer = 0 To 1
doc.Add(New TextBlock("This is header and footer generation pdf file.") With {.Class = "content"})
doc.Add(New PageBreak())
Next i
' Generate PDF
Using stream As Stream = File.Create("out.pdf")
doc.Write(stream, resourceManager)
End Using
Process.Start("out.pdf")
輸出內容如下:
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");
Imports IronPdf
' Cryptographically sign an existing PDF in 1 line of code!
Call (New IronPdf.Signing.PdfSignature("Iron.p12", "123456")).SignPdfFile("any.pdf")
'''*** Advanced example for more control ****
' 1. Create a PDF
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim 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.
Dim 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")
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();
}
}
}
Imports System
Imports System.IO
Imports Apitron.PDF.Rasterizer
Imports Apitron.PDF.Kit.FixedLayout
Imports Apitron.PDF.Kit
Imports Apitron.PDF.Kit.Styles
Imports Apitron.PDF.Kit.Signatures
Imports Apitron.PDF.Kit.Interactive.Annotations
Module Module1
Sub Main(args As String())
Dim fileName As String = "signedTwice.pdf"
Using stream As Stream = File.Create(fileName)
Dim doc As New FlowDocument() With {.Margin = New Thickness(10)}
doc.Add(New TextBlock("Signed using Apitron PDF Kit for .NET"))
doc.Write(stream, New ResourceManager())
End Using
' Save
Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", New Boundary(10, 750, 110, 800))
End Sub
' Implementation of Sign Method
Private Sub Sign(pathToDocument As String, pathToCertificate As String, password As String, pathToSignatureImage As String, signatureViewLocation As Boundary)
' Open existing document and sign once
Using inputStream As Stream = New FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite)
Using doc As New FixedDocument(inputStream)
Dim imageResourceId As String = Guid.NewGuid().ToString("N")
Dim signatureFieldId As String = 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
Dim signatureField As New SignatureField(signatureFieldId)
Using signatureDataStream As Stream = File.OpenRead(pathToCertificate)
signatureField.Signature = Signature.Create(New Pkcs12Store(signatureDataStream, password))
End Using
' Add signature fields to the document
doc.AcroForm.Fields.Add(signatureField)
' Create first signature view using the image resource
Dim signatureView As 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()
End Using
End Using
End Sub
End Module
庫的輸出內容大致相同。 您可以清楚地看到,IronPDF 在操作 PDF 內容時更加簡單方便。 輸出的 PDF 上印有證書和簽名。
使用 Bootstrap 5 和 IronPDF 製作作品集圖庫
IronPDF 的 Chrome V8 渲染引擎完全支援現代 Bootstrap 5 组件,使您能够生成具有專业组合图庫的视觉效果极佳的 PDF 文檔。 本範例展示了網格佈局、懸浮效果、漸層覆蓋和類別徽章 - 這些功能若使用 Apitron PDF SDK 之類的傳統 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");
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");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim portfolioGallery As String = "
<!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>"
Dim pdf = renderer.RenderHtmlAsPdf(portfolioGallery)
pdf.SaveAs("portfolio-gallery.pdf")
此代碼可產生專業的 PDF 作品集,並採用回應式網格佈局、視覺化類別徽章、漸層覆蓋和懸浮效果。 Chrome 渲染引擎保留了所有 Bootstrap 造型、CSS Grid 布局和自定义 CSS 属性 - 这些功能是傳统 PDF 庫难以复制的。
主要優勢 vs Apitron PDF SDK:
- 原生 Bootstrap 5 支援,無需轉換
- CSS Grid 和 Flexbox 佈局完美呈現
- 漸層背景和現代 CSS 效果
- 以更高品質的輸出簡化程式碼
如需完整的 Bootstrap PDF 生成指南,請參閱 HTML to PDF Bootstrap 指南。
6.定價與授權
IronPDF 定價與授權
IronPDF 是一個 C# 函式庫,可免費用於開發,並可隨時取得商業使用授權。適用於單一開發人員、代理商、跨國組織的專案授權,以及 SaaS 和 OEM 的再散佈,都是可以取得的。 所有授權均提供 30 天退款保證、一年支援與升級、開發/暫存/生產有效性,以及永久授權 (一次性購買)。
Lite 套餐售價為 $999,無任何經常性費用。 IronPDF產品授權頁面上提供了更多詳細資訊以及選擇最佳授權的協助。
IronPDF 許可證
Apitron PDF Kit 定價與授權
目前有兩種授權方案 - 現代與傳統。 如果您已經擁有許可證,則在您的許可證到期之前,傳統許可證方案對您仍然有效。 之後,您必須聯絡客戶支援以進行交接。 現代的授權方案僅適用於新客戶。
在現代方案下,有三種授權層級:
- Evaluation - 三個月的評估期間,可使用功能完整的產品。 只需從 NuGet 下載套件,即可開始開發。
- Community - 在您的非商業專案中使用功能完整的產品,不需支付任何費用。 必須通過審核。
- Commercial - 以上未描述的任何使用情況。 價格取決於使用模式。
結論
IronPDF 函式庫可從 HTML、JS、CSS、JPG、PNG、GIF 和 SVG 等文件類型建立像素完美的 PDF。 Chromium 引擎可協助渲染 HTML 檔案或 URL,以提供完美的 PDF 輸出。
Apitron 可讓您使用固定版面 API 來建立 PDF,並與 PDF 規格 100% 相容。 作為一種類似 HTML 和 CSS 的樣式驅動內容產生方法,此固定版面 API 可讓您在幾分鐘內建立令人驚豔的報表、帳單、目錄等。 它也支援 XML 範本的建立。
Apitron PDF 的授權價格不在其網站上。您必須聯絡支援人員,並根據您的用途取得報價。 另一方面,IronPDF 在其網站上展示了非常清晰的授權套件。這使得 IronPDF 從競爭對手中脫穎而出,讓使用者可以根據自己的需求進行明智的選擇。
使用 IronPDF,您可以比使用 Apitron PDF 更輕鬆地處理 PDF 檔案。 IronPDF 可讓使用者以較少的程式碼行數完成具挑戰性的 PDF 工作。 IronPDF 提供從多種檔案類型產生 PDF 的多種方法,而 Apitron 只能將 XML 文件轉換為 PDF 文件。 與 Apitron 相比,IronPDF 無需增加任何技術選項即可達到完美輸出。
Iron Software 的所有客戶都可以選擇以購買其中兩項產品的價格購買該公司的全部五項產品。 請嘗試 免費試用 30 天的 IronPDF 以測試其完整功能。 購買全套 Iron Software 產品 at IronSoftware.com。
常見問題解答
如何在 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 則較繁瑣。

