Scryber.Core與IronPDF:技術比較指南
當 .NET 開發者評估用於文件生成和操作的 PDF 程式庫時,XFINIUM.PDF 作為一個具有全面低層次 PDF 工具的跨平台選擇出現。 然而,其基於座標的圖形編程模型與 HTML 為中心的方法具有顯著差異。 此技術比較檢視了 XFINIUM.PDF 與 IronPDF,幫助架構師和開發者了解 PDF 生成哲學、API 設計和現代網頁內容支援的根本差異。
了解 XFINIUM.PDF
XFINIUM.PDF 是一個完全以 C# 開發的商業跨平台 PDF 程式庫,旨在服務初學者和專業 PDF 開發者。 該程式庫提供廣泛的功能,包括 PDF 生成、表單填寫、PDF 組合構建、內容編輯和多頁 TIFF 轉換。
XFINIUM.PDF 提供兩個版本:用於 PDF 建立和編輯的生成版本,以及新增渲染和顯示功能的查看版本。 該程式庫提供跨平台的全面 PDF 操作工具。
然而,XFINIUM.PDF 與以網頁為中心的 PDF 程式庫運作在根本上不同的範式上:
- 基於座標的 API: 需要利用像
DrawString("text", font, brush, 50, 100)的像素座標進行手動定位 - 沒有原生 HTML 支援: 無法將 HTML/CSS 轉換為 PDF—依賴於低層次的繪圖原語
- 手動字體管理: 必須明確地建立和管理字體物件
- 無 CSS 樣式支援: 無現代網頁樣式的支援—顏色、字體和佈局必須手動處理
- 無JavaScript渲染: 僅靜態內容—無法渲染動態網頁內容
- 複雜的文字佈局: 需要手動進行文字測量和換行計算
圖形編程模型
XFINIUM.PDF 迫使開發者如同圖形程式設計師而非文件設計師進行思考:
// XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, new XPoint(50, 50));
page.Graphics.DrawString("Customer:", labelFont, brush, new XPoint(50, 80));
page.Graphics.DrawString(customer.Name, valueFont, brush, new XPoint(120, 80));
page.Graphics.DrawLine(pen, 50, 100, 550, 100);
// ... hundreds of lines for a simple document// XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, new XPoint(50, 50));
page.Graphics.DrawString("Customer:", labelFont, brush, new XPoint(50, 80));
page.Graphics.DrawString(customer.Name, valueFont, brush, new XPoint(120, 80));
page.Graphics.DrawLine(pen, 50, 100, 550, 100);
// ... hundreds of lines for a simple document' XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, New XPoint(50, 50))
page.Graphics.DrawString("Customer:", labelFont, brush, New XPoint(50, 80))
page.Graphics.DrawString(customer.Name, valueFont, brush, New XPoint(120, 80))
page.Graphics.DrawLine(pen, 50, 100, 550, 100)
' ... hundreds of lines for a simple document由於需求變更,此方法成為維護挑戰,因為每個元素的位置必須在內容移動時重新計算。
了解IronPDF
IronPDF 採用網頁為中心的方法來生成 PDF,使用 Chromium 渲染引擎將 HTML、CSS 和JavaScript直接轉換為 PDF 文件。 IronPDF 使開發者可以使用熟悉的網頁技術來建立文件,而不是基於座標繪圖。
關鍵特性包括:
- 基於 HTML/CSS 的設計: 使用標準網頁技術進行文件佈局
- Chromium 渲染引擎: 通過現代瀏覽器技術提供全面的 CSS3 和JavaScript支援
- 自動佈局: 無需手動座標計算—內容自然流動
- 現代網頁標準: CSS Grid、Flexbox、網頁字體和 ES2024 JavaScript
- URL-to-PDF 轉換: 將即時網頁渲染為 PDF
- 大型社群: 全面的文件、教程和支援資源
功能比較
下表突顯了 XFINIUM.PDF 與IronPDF之間的根本差異:
| 功能 | XFINIUM.PDF | IronPDF |
|---|---|---|
| HTML到PDF | 有限的 HTML 支援,專注於程式化 PDF 建立 | 全面的 HTML-to-PDF 轉換,具有全面支援 |
| 社群和支援 | 較小的社群,可用的線上資源較少 | 大型社群,擁有廣泛的文件和教程 |
| 授權 | 商業化,基於開發者的授權 | 商業 |
| 跨平台支援 | 強大的跨平台能力 | 也支援跨平台操作 |
| 專業功能 | 全面的 PDF 編輯工具 | 先進的 HTML 渲染與 PDF 功能 |
詳細功能比較
| 功能 | XFINIUM.PDF | IronPDF |
|---|---|---|
| 內容建立 | ||
| HTML到PDF | 有限(PdfHtmlTextElement) | 全面支持 Chromium 渲染 |
| URL到PDF | 無 | 是 |
| CSS支持 | 無 | 完全支持 CSS3 |
| JavaScript | 無 | 完整的ES2024 |
| Flexbox/Grid | 無 | 是 |
| Web 字體 | 無 | 是 |
| SVG 支援 | 有限 | 完整 |
| 佈局 | ||
| 自動佈局 | 無 | 是 |
| 自動分頁 | 無 | 是 |
| 手動定位 | 需要 | 可選(CSS 定位) |
| 表格 | 手動繪圖 | HTML <table> |
| PDF 操作 | ||
| 合併PDFs | 是 | 是 |
| 切分PDF | 是 | 是 |
| 水印 | 手動繪圖 | 內建支持 |
| 頁眉/頁腳 | 手動每頁 | 自動 |
| 開發 | ||
| 學習曲線 | 高(座標系統) | 低(HTML/CSS) |
| 程式碼冗長 | 非常高 | 低 |
| 維護 | 困難 | 簡單 |
| 跨平台 | 是 | 是 |
API 架構差異
XFINIUM.PDF 和IronPDF之間的架構差異代表了生成 PDF 的根本不同的方法。
XFINIUM.PDF 流文件模式
XFINIUM.PDF 使用 PdfFlowDocument 和 PdfFlowContent 物件進行多步流程:
// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using Xfinium.Pdf.Actions;
using Xfinium.Pdf.FlowDocument;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfFlowDocument flowDocument = new PdfFlowDocument();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>";
PdfFlowContent content = new PdfFlowContent();
content.AppendHtml(html);
flowDocument.AddContent(content);
flowDocument.RenderDocument(document);
document.Save("output.pdf");
}
}// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using Xfinium.Pdf.Actions;
using Xfinium.Pdf.FlowDocument;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfFlowDocument flowDocument = new PdfFlowDocument();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>";
PdfFlowContent content = new PdfFlowContent();
content.AppendHtml(html);
flowDocument.AddContent(content);
flowDocument.RenderDocument(document);
document.Save("output.pdf");
}
}Imports Xfinium.Pdf
Imports Xfinium.Pdf.Actions
Imports Xfinium.Pdf.FlowDocument
Imports System.IO
Module Program
Sub Main()
Dim document As New PdfFixedDocument()
Dim flowDocument As New PdfFlowDocument()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>"
Dim content As New PdfFlowContent()
content.AppendHtml(html)
flowDocument.AddContent(content)
flowDocument.RenderDocument(document)
document.Save("output.pdf")
End Sub
End Module此模式需要建立多個文件物件,將內容新增到流容器,渲染到固定文件,然後保存。 通過 AppendHtml 的 HTML 支援與全瀏覽器渲染相比較為有限。
IronPDF精簡模式
IronPDF 使用 ChromePdfRenderer 類直接進行 HTML-to-PDF 轉換:
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ClassChromePdfRenderer 類使用 Chromium 渲染引擎處理具有完整 CSS3 和JavaScript支援的 HTML。 有關全面的HTML轉換指導,請參見HTML轉PDF教程。
PDF合併操作
將多個 PDF 文件合併揭示了兩個庫之間的 API 複雜性差異。
XFINIUM.PDF 手動頁迴圈
XFINIUM.PDF 需要打開文件流、遍歷頁面並手動將每個頁面新增到輸出文件中:
// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument output = new PdfFixedDocument();
FileStream file1 = File.OpenRead("document1.pdf");
PdfFixedDocument pdf1 = new PdfFixedDocument(file1);
FileStream file2 = File.OpenRead("document2.pdf");
PdfFixedDocument pdf2 = new PdfFixedDocument(file2);
for (int i = 0; i < pdf1.Pages.Count; i++)
{
output.Pages.Add(pdf1.Pages[i]);
}
for (int i = 0; i < pdf2.Pages.Count; i++)
{
output.Pages.Add(pdf2.Pages[i]);
}
output.Save("merged.pdf");
file1.Close();
file2.Close();
}
}// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument output = new PdfFixedDocument();
FileStream file1 = File.OpenRead("document1.pdf");
PdfFixedDocument pdf1 = new PdfFixedDocument(file1);
FileStream file2 = File.OpenRead("document2.pdf");
PdfFixedDocument pdf2 = new PdfFixedDocument(file2);
for (int i = 0; i < pdf1.Pages.Count; i++)
{
output.Pages.Add(pdf1.Pages[i]);
}
for (int i = 0; i < pdf2.Pages.Count; i++)
{
output.Pages.Add(pdf2.Pages[i]);
}
output.Save("merged.pdf");
file1.Close();
file2.Close();
}
}Imports Xfinium.Pdf
Imports System.IO
Module Program
Sub Main()
Dim output As New PdfFixedDocument()
Dim file1 As FileStream = File.OpenRead("document1.pdf")
Dim pdf1 As New PdfFixedDocument(file1)
Dim file2 As FileStream = File.OpenRead("document2.pdf")
Dim pdf2 As New PdfFixedDocument(file2)
For i As Integer = 0 To pdf1.Pages.Count - 1
output.Pages.Add(pdf1.Pages(i))
Next
For i As Integer = 0 To pdf2.Pages.Count - 1
output.Pages.Add(pdf2.Pages(i))
Next
output.Save("merged.pdf")
file1.Close()
file2.Close()
End Sub
End Module此方法需要顯式的流管理,手動遍歷每個文件的頁面及小心清理文件句柄。
IronPDF靜態合併方法
IronPDF 提供一個靜態 Merge 方法,內部處理所有的複雜性:
// NuGet: Install-Package IronPdf
using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}Imports IronPdf
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End ClassPdfDocument.Merge 方法 消除了手動頁面迭代和流管理,顯著降低程式碼複雜性。
建立帶有文字和圖像的文件
使用混合內容構建文件展示了基於座標圖形與基於 HTML 設計之間的範式差異。
XFINIUM.PDF 圖形方法
XFINIUM.PDF 需要建立字體物件、畫筆物件、將圖像載入到特定圖像類別中,並在精確的座標上繪製每個元素:
// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using Xfinium.Pdf.Core;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
PdfStandardFont font = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
PdfBrush brush = new PdfBrush(PdfRgbColor.Black);
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50);
FileStream imageStream = File.OpenRead("image.jpg");
PdfJpegImage image = new PdfJpegImage(imageStream);
page.Graphics.DrawImage(image, 50, 100, 200, 150);
imageStream.Close();
document.Save("output.pdf");
}
}// NuGet: Install-Package Xfinium.Pdf
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using Xfinium.Pdf.Core;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
PdfStandardFont font = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
PdfBrush brush = new PdfBrush(PdfRgbColor.Black);
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50);
FileStream imageStream = File.OpenRead("image.jpg");
PdfJpegImage image = new PdfJpegImage(imageStream);
page.Graphics.DrawImage(image, 50, 100, 200, 150);
imageStream.Close();
document.Save("output.pdf");
}
}Imports Xfinium.Pdf
Imports Xfinium.Pdf.Graphics
Imports Xfinium.Pdf.Core
Imports System.IO
Class Program
Shared Sub Main()
Dim document As New PdfFixedDocument()
Dim page As PdfPage = document.Pages.Add()
Dim font As New PdfStandardFont(PdfStandardFontFace.Helvetica, 24)
Dim brush As New PdfBrush(PdfRgbColor.Black)
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50)
Dim imageStream As FileStream = File.OpenRead("image.jpg")
Dim image As New PdfJpegImage(imageStream)
page.Graphics.DrawImage(image, 50, 100, 200, 150)
imageStream.Close()
document.Save("output.pdf")
End Sub
End Class這需要管理 PdfRgbColor 和 PdfJpegImage 物件,對文字和圖像進行顯式座標定位。
IronPDFHTML 方法
IronPDF 使用標準的嵌入圖片的 HTML:
// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string imageBase64 = Convert.ToBase64String(File.ReadAllBytes("image.jpg"));
string html = $@"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string imageBase64 = Convert.ToBase64String(File.ReadAllBytes("image.jpg"));
string html = $@"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}Imports IronPdf
Imports System.IO
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim imageBase64 As String = Convert.ToBase64String(File.ReadAllBytes("image.jpg"))
Dim html As String = $"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ClassHTML 自動處理佈局-無需座標計算,不需管理字體物件,且圖像使用標準 <img> 標籤或 base64 編碼自然嵌入。
API映射參考
評估從 XFINIUM.PDF 過渡到IronPDF的團隊,將發現此映射有助於理解概念等價性:
| XFINIUM.PDF | IronPDF |
|---|---|
PdfFixedDocument | ChromePdfRenderer |
PdfPage | 自動 |
page.Graphics.DrawString() | HTML文字元素 |
page.Graphics.DrawImage() | <img> 標籤 |
page.Graphics.DrawLine() | CSS border 或 <hr> |
page.Graphics.DrawRectangle() | CSS border 在 <div> 上 |
PdfUnicodeTrueTypeFont | CSS font-family |
PdfRgbColor | CSS color |
PdfBrush | CSS 屬性 |
PdfPen | CSS border |
PdfHtmlTextElement | RenderHtmlAsPdf() |
document.Save(stream) | pdf.SaveAs() 或 pdf.BinaryData |
PdfStringAppearanceOptions | CSS樣式 |
PdfStringLayoutOptions | CSS 佈局 |
當團隊考慮從 XFINIUM.PDF 遷移到IronPDF時
有幾種情況通常導致開發團隊評估IronPDF作為 XFINIUM.PDF 的替代方案:
現代網頁內容需求
構建從網頁模板、儀表板或報告生成 PDF 的應用程式的團隊發現 XFINIUM.PDF 的基於座標的方法有限。IronPDF的 Chromium 引擎渲染現代的 CSS Grid、Flexbox 和JavaScript驅動的內容,這是 XFINIUM.PDF 無法支援的。
維護和程式碼複雜性
XFINIUM.PDF 的基於座標的 API 產生冗長程式碼,隨著文件佈局的演變,變得難以維護。 一個簡單的發票文件可能需要數百行的定位程式碼,而使用IronPDF則只需數十行的 HTML/CSS。
URL-to-PDF 功能
XFINIUM.PDF 無法將即時網頁渲染為 PDF - 這需外部 HTML 解析程式庫。IronPDF認提供原生 URL-to-PDF 轉換,具有完整的JavaScript執行和動態內容支援。
開發者熟悉度
擁有強大網頁開發技能的團隊發現學習基於座標的 PDF 生成的學習曲線陡峭。HTML 和 CSS 是廣泛理解的技術,使得IronPDF的方法對無專門 PDF 知識的開發者更具吸引力。
自動佈局和分頁
XFINIUM.PDF 需要手動跟踪 Y 位置和當內容超過頁面邊界時進行顯式建立新頁面。IronPDF根據 CSS 規則和內容流自動處理分頁。
常見遷移考量
團隊從 XFINIUM.PDF 過渡到IronPDF應考慮這些技術差異:
從基於座標到流佈局
XFINIUM.PDF 需要每個元素的精確 X,Y 座標。IronPDF預設使用 HTML 流佈局。 對於需要絕對定位的情況,CSS 提供了這種能力:
.positioned-element {
position: absolute;
top: 100px;
left: 50px;
}字體物件到 CSS 字體系列
XFINIUM.PDF 明確建立 PdfUnicodeTrueTypeFont 物件。IronPDF使用 CSS 字體系列,具有自動字體處理:
<style>
body { font-family: Arial, sans-serif; }
h1 { font-family: 'Times New Roman', serif; font-size: 24px; }
</style><style>
body { font-family: Arial, sans-serif; }
h1 { font-family: 'Times New Roman', serif; font-size: 24px; }
</style>顏色物件到 CSS 顏色
XFINIUM.PDF 需要 PdfRgbColor 和 PdfBrush 物件。IronPDF使用標準 CSS 顏色:
.header { color: navy; background-color: #f5f5f5; }
.warning { color: rgb(255, 0, 0); }
.info { color: rgba(0, 0, 255, 0.8); }手動到自動分頁
XFINIUM.PDF 需要跟踪 Y 位置並手動建立新頁面。IronPDF提供帶有 CSS 控制的自動分頁:
.section { page-break-after: always; }
.keep-together { page-break-inside: avoid; }IronPDF的額外功能
除了核心比較點外,IronPDF 提供的文件操作功能補充其 HTML 渲染:
.NET相容性和未來準備
兩個程式庫都支持跨平台 .NET 開發。IronPDF維持活躍開發,定期更新,確保與 .NET 8、.NET 9 和預計 2026 年版的 .NET 10 相容。此程式庫的 HTML/CSS 方法與現代網頁開發實踐保持一致,充分利用了 .NET 開發者已經擁有的技能。
結論
XFINIUM.PDF 和IronPDF表示在 .NET 中生成 PDF 的根本不同方法。 XFINIUM.PDF 的基於座標的圖形 API 提供底層控制,但需要顯著的程式碼來進行文件佈局——每個元素都需要明確定位、字體物件以及顏色管理。 隨著文件複雜性的增加,這種方法變得越來越難以維護。
IronPDF 的基於 HTML/CSS 的方法利用 Chromium 渲染引擎將 PDF 生成視為網頁渲染。 開發者使用熟悉的 HTML、CSS 和 JavaScript,而不是學習基於座標的圖形 API。自動佈局、分頁和現代網頁標準支持(CSS Grid、Flexbox、ES2024 JavaScript)顯著降低程式碼複雜性。
對於構建生成網路報告、儀表板或動態文件的應用程式的團隊而言,IronPDF 的方法與現代開發實踐自然一致。 對於需要對每個文件元素進行像素級控制且願意投入於基於座標的編程模型的團隊,XFINIUM.PDF 的圖形 API 提供此能力。
最終選擇取決於您團隊的要求:如果您的 PDF 來自網頁內容或您更喜歡使用 HTML/CSS 進行文件設計,IronPDF 的方法提供了顯著的生產力優勢。 如果您正在構建需要精準定位的高度專業化的 PDF 內容,且您的團隊具備圖形編程專長,XFINIUM.PDF 的低層 API 可能滿足這些需求。
如需額外的實施指南,請探索IronPDF文件和教程,涵蓋特定用例和高級功能。
