跳至頁尾內容
PDF工具

如何將文件儲存為PDF

在C#中處理PDF文件可能對開發者來說是個挑戰。 在建立這些文件的內容時需要考慮很多因素,尤其是在從不同格式轉換內容到PDF時。 自動化現在是軟體開發流程中的關鍵。 這些挑戰已被設計用於幫助閱讀、寫入、建立和修改PDF文件,以及編輯其屬性並將其從其他格式轉換的程式庫所解決。

本文比較了兩個用於.NET和.NET Core的PDF程式庫:

  • IronPDF程式庫
  • Apitron PDF Kit

IronPDF和Apitron PDF Kit是為.NET和.NET Core提供PDF操作功能的程式庫。 它們可用於文件欄位轉換和操作任務。 它們還允許建立書籤。 下一步是決定哪個C#.NET PDF程式庫最適合我們的.NET項目。 本比較文章將幫助您在這兩個PDF程式庫之間做出決定。

首先,讓我們探索這兩個程式庫提供的功能,然後進行比較。

Apitron PDF Kit程式庫及其特點

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文字和提取圖形變得簡單。

IronPDF的突出功能包括:

  • 使用HTML4/5、CSS和JavaScript建立PDF文件
  • 通過自定義的網路登錄憑據、使用者代理、代理、Cookie、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 Kit安裝
  3. 建立PDF文件
  4. 在PDF中建立頁眉和頁腳
  5. 數位簽名PDF
  6. 價格和授權

1. IronPDF安裝

下載和安裝IronPDF程式庫有四種方法。 這些是:

  1. 使用NuGet包管理器
  2. 開發者命令提示符
  3. 直接下載NuGet包
  4. 下載IronPDF .DLL程式庫

1.1. 使用NuGet包管理器

要安裝IronPDF,只需在解決方案瀏覽器中右鍵單擊您的項目。 這將打開NuGet包管理器。

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 1: 使用解決方案瀏覽器存取NuGet包管理器

使用解決方案瀏覽器存取NuGet包管理器

選中後,瀏覽IronPDF包並按照下面的截圖安裝。

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 2: 使用NuGet包管理器安裝IronPDF程式庫

使用NuGet包管理器安裝IronPDF程式庫

1.2. 使用開發者命令提示符

您還可以通過開發者命令提示符安裝IronPDF。

  • 打開開發者命令提示符 ——通常在Visual Studio文件夾中找到
  • 輸入以下命令:
Install-Package IronPdf
  • 按Enter鍵
  • 這將下載並安裝該包
  • 重新載入您的項目並開始使用

1.3. 直接下載NuGet包

IronPDF也可以直接通過存取IronPDF NuGet包網站並下載該包來進行安裝。 步驟是:

  • 導航到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。
  • 在當前項目中點擊安裝。
A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 3: 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;
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
$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");
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")
$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");
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")
$vbLabelText   $csharpLabel

輸出如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 4: IronPDF 從URL和HTML CSS字串生成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

將此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
$vbLabelText   $csharpLabel

輸出如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 5: Apitron PDF文件

Apitron PDF文件

如果比較IronPDF和Apitron的輸出,我們可以清楚地看到IronPDF使用HTML渲染建立了令人印象深刻的文件,甚至未縮放圖像大小。而Apitron僅在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")
$vbLabelText   $csharpLabel

輸出如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 6: IronPDF頁眉和頁腳

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&nbsp;", 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&nbsp;", 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&nbsp;", 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")
$vbLabelText   $csharpLabel

輸出如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 7: Apitron頁眉和頁腳

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")
$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();
        }
    }
}
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
$vbLabelText   $csharpLabel

兩個程式庫的輸出基本相同。 您可以清晰地看到IronPDF在操作PDF內容方面更簡單更方便。 輸出的PDF上帶有證書和簽名。

將Bootstrap 5與IronPDF用於組合庫

IronPDF的Chrome V8渲染引擎完全支持現代Bootstrap 5組件,使您能夠生成具有專業組合庫的視覺驚人的PDF文件。 此範例展示了網格佈局、懸停效果、漸變疊加和類別徽章——這些功能用傳統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");
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")
$vbLabelText   $csharpLabel

此程式碼生成了一個專業的PDF組合,具有響應式網格佈局、視覺類別徽章、漸變疊加和懸停效果。 Chrome渲染引擎保留了所有Bootstrap樣式、CSS網格佈局和自定義CSS屬性——這些是傳統PDF程式庫難以復制的功能。

與Apitron PDF SDK的主要優勢:

  • 原生支持Bootstrap 5而無需轉換
  • CSS網格和Flexbox佈局完美渲染
  • 漸變背景和現代CSS效果
  • 更簡單的程式碼與更高質量的輸出

關於Bootstrap PDF生成的完整指導,可參見HTML to PDF Bootstrap指南

6. 價格和授權

IronPDF定價和許可

IronPDF是一個C#程式庫,對開發免費使用,並可隨時獲得授權用於商業用途。項目授權對單個開發者、機構和跨國公司以及SaaS和OEM再分發均可存取。 所有授權均提供30天退款保證、一年支援和升級、開發/試用/生產有效性以及永久授權(一次性購買)。

Lite包可用於$999,無需經常性費用。 有關選擇最佳授權的更多詳細資訊和協助,可存取IronPDF產品授權頁面

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 8: IronPDF授權

IronPDF授權

Apitron PDF Kit價格和授權

目前正在使用兩種授權方案 - 現代和舊版。 如果您已擁有授權,那麼舊版授權方案將在授權到期之前對您仍然有效。 之後,您需要聯繫客戶支援以轉換方案。 現代授權方案僅適用於新客戶。

在現代方案下,有三個授權級別:

  • 評估 - 三個月的評估期內使用功能完善的產品。 只需從NuGet下載包,然後開始開發。
  • 社區 - 在非商業项目中免費使用功能齊全的產品。 需要獲得批准。
  • 商業 - 任何上述未描述的使用情形。 價格根據使用模式而定。

結論

IronPDF程式庫從HTML、JS、CSS、JPG、PNG、GIF和SVG等文件格式建立像素完美的PDF。 Chromium引擎有助於渲染HTML文件或URL,以給出完美的PDF作為輸出。

Apitron讓您使用固定佈局API建立PDF,該API實施已達到100%的PDF規範相容。 作為一種類似於HTML和CSS的樣式驅動內容生成方法,此固定佈局API使您能夠在幾分鐘內建立令人驚豔的報告、賬單、目錄等。 它還支持建立XML模板。

Apitron PDF的授權價格未在其網站上發布。您需聯繫支援並根據您的使用情況獲得報價。 另一方面,IronPDF在其網站上顯示了非常清楚的授權包。這使得IronPDF在競爭中脫穎而出,並讓使用者可以根據自己的需求做出明智的選擇。

使用IronPDF,您可以比使用Apitron PDF更容易工作PDF文件。 IronPDF允許使用者在處理挑戰性的PDF工作時寫下更少的程式碼行。 IronPDF提供多種方法來從多種文件型別生成PDF,而Apitron僅能將XML文件轉換為PDF文件。 在IronPDF中無需新增任何技術選項即可達到完美的輸出,與Apitron相比。

所有Iron Software客戶都可以以兩個產品的價格購買公司全部五個產品。 試用免費,30天的IronPDF試用版來測試其所有功能。 購買Iron Software產品的全套在IronSoftware.com

請注意Apitron PDF Kit是其各自所有者的註冊商標。 本網站與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 進行數位簽名?

using 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 允許您通過 AddTextHeaderAddTextFooter 方法輕鬆地將頁眉和頁腳新增到 PDF 中。

Apitron PDF Kit 提供哪些授權選項?

Apitron PDF Kit 提供三個月的評估期和非商業專案的社群授權。商業用途則需要直接聯絡他們以獲取報價。

哪一個 PDF 程式庫對 .NET 開發更容易使用?

IronPDF 通常對 .NET 開發更容易使用,提供更簡單的 API,並且相比 Apitron PDF Kit,複雜任務所需的程式碼行更少。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話