IronPDF與HiQPdf C#之比較
IronPDF 和 HiQPdf 的概述
對於使用 .NET 的開發人員而言,找到合適的 PDF 解決方案對建立功能豐富的應用程式至關重要,而在現今這個時代,提供 PDF 轉換技術的產品數量不斷增加,要找到符合您需求的合適工具可說是難上加難。 在本比較中,我們將評估 IronPDF 和 HiQPdf,這兩個在 .NET 專案中使用的熱門 HTML-to-PDF 函式庫。 雖然這兩個函式庫都提供強大的 PDF 產生功能,但 IronPDF 因其更全面的功能、跨平台相容性和直覺式 API 而脫穎而出。
無論您是在尋找進階的編輯選項、跨平台支援,或是易用性,這份 IronPDF 與 HiQPdf 的並列比較都能幫助您做出明智的決定。
主要功能一覽
IronPDF 是適用於 C# 和 .NET 的多功能 PDF 函式庫,可實現無縫 PDF 生成、編輯和操作。 支援 .NET 8、7、6 和 Core,配備豐富的工具集,讓開發人員可以處理從 HTML 到 PDF 的轉換,到加密和數位簽章等進階安全選項。 有了 IronPDF,您可以在每個 PDF 頁面上新增文字或 HTML 標題、使用網頁字型以獲得更好的文字自訂功能、擷取文字、建立時尚的 PDF 文件等!
另一方面,HiQPdf 主要專注於 HTML 至 PDF 的轉換,提供對 CSS3、JavaScript、SVG 和 Canvas 元素的穩固支援。 雖然 HiQPdf 可提供可靠的 PDF 生成功能,但它缺乏 IronPDF 所提供的某些進階功能和靈活性,尤其是在跨平台相容性和詳細的文件編輯方面。
主要功能比較:IronPDF 與 HiQPdf 的 PDF 功能比較。
IronPDF 功能
- PDF轉換: IronPDF 可以將 HTML 轉換為 PDF,它完全支援現代網路標準,您可以放心,IronPDF 會從您的 HTML 頁面或內容中持續傳回像素完美的 PDF。 IronPDF 也可以轉換其他格式的 PDF 檔案,例如 DOCX、圖片、RTF 等。
- PDF生成:使用 IronPDF,您可以從 URL、ASPX 檔案或 HTML 字串產生 PDF。
- 安全功能:借助 IronPDF 的安全功能,您可以始终确保任何敏感 PDF 文件的安全。 使用 IronPDF 加密您的 PDF 檔案、設定密碼,以及為 PDF 檔案設定權限。
- PDF編輯功能:使用 IronPDF,您可以處理現有的 PDF 文件、編輯它們,並輕鬆讀取 PDF 檔案。 IronPDF 提供的編輯功能包括新增頁首和頁尾,在 PDF 頁面上印製文字和圖片,在 PDF 上新增自訂水印,處理 PDF 表單,以及分割或合併 PDF 檔案。
- 整合:與 ASP.NET 和 MVC 應用程式無縫整合。
- PDF 版本支援: 可支援 PDF 版本 1.2-1.7
如需 IronPDF 功能的完整清單,請造訪 IronPDF功能。
HiQPdf 功能:
- HTML 至 PDF 轉換:支援 HTML5、CSS3、JavaScript、SVG 和 canvas 元素。 HiQPdf 能以精確的保真度處理複雜的頁面佈局。
- JavaScript 在 PDF 中執行:在轉換後的 PDF 內執行 JavaScript,啟用互動功能。
- 註解與書籤:新增標準的 PDF 註解,例如註解和反白。
- 自訂紙張尺寸支援:提供在 PDF 建立過程中定義自訂紙張尺寸的選項。
- 基本密碼保護:使用基本密碼選項保護 PDF,以限制存取和修改。
- Page Break CSS 屬性: 使用 CSS 屬性
'page-break-before:always'控制您所產生的 PDF 文件中的分頁符號。 - Merge & Split PDFs:將多個 PDF 合併為單一文件,或將大型 PDF 分割為較小的檔案,以便更好地管理。
IronPDF 擁有更廣泛的功能集,提供更先進的 PDF 編輯、安全性和跨平台相容性,因此比 HiQPdf 更有優勢。
跨平台相容性
IronPDF 與 HiQPdf 的主要差異之一在於跨平台相容性。 IronPdf提供對 Windows、Linux 和 macOS 的無縫支援,使其成為在不同環境中工作的開發人員的絕佳選擇。 它也與 Docker、Azure、AWS 和主要 .NET 版本相容,包括 .NET 8、7、6 和 .NET Core。
HiQPdf 雖然功能強大,但其平台支援較為有限,主要著重於 Windows 環境。
IronPDF 與 HiQPdf 之間的頂尖亮點功能比較與程式碼範例。
HTML 至 PDF 轉換
IronPDF:
using IronPdf;
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
// Render HTML to PDF with assets
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");using IronPdf;
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
// Render HTML to PDF with assets
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");Imports IronPdf
' Create a new PDF renderer
Private renderer = New ChromePdfRenderer()
' Render HTML to PDF
Private pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
pdf.SaveAs("output.pdf")
' Render HTML to PDF with assets
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")HiQPdf:
// Create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// Convert HTML code to a PDF file
htmlToPdfConverter.ConvertHtmlToFile("<b>Hello World</b>", null, "result.pdf");// Create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// Convert HTML code to a PDF file
htmlToPdfConverter.ConvertHtmlToFile("<b>Hello World</b>", null, "result.pdf");' Create the HTML to PDF converter
Dim htmlToPdfConverter As New HtmlToPdf()
' Convert HTML code to a PDF file
htmlToPdfConverter.ConvertHtmlToFile("<b>Hello World</b>", Nothing, "result.pdf")對於 HTML到PDF的轉換,IronPDF提供了一個簡單的方法,通過使用ChromePdfRenderer將HTML內容渲染成PDF,無論您處理的是HTML文件、字符串還是URL。 IronPDF 也支援進階方案,例如以圖片等本機資產渲染 HTML。 另一方面,HiQPdf 使用 HtmlToPdf 類,HTML 內容會直接轉換成 PDF 檔案,並進行更基本的設定。這兩個函式庫都能有效處理 HTML 到 PDF 的轉換,但 IronPDF 在資產處理上提供了額外的彈性。
加密 PDF 文件
IronPDF範例:
using IronPdf;
// Load an existing PDF
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
// Set metadata and remove existing passwords
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;
// Update security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Set a new password and save the document
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");using IronPdf;
// Load an existing PDF
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
// Set metadata and remove existing passwords
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;
// Update security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Set a new password and save the document
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");Imports IronPdf
' Load an existing PDF
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")
' Set metadata and remove existing passwords
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now
' Update security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
' Set a new password and save the document
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")HiQPdf:
// Create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// Set encryption mode and level
htmlToPdfConverter.Document.Security.EncryptionMode = GetSelectedEncryptionMode();
htmlToPdfConverter.Document.Security.EncryptionLevel = GetSelectedEncryptionLevel();
// Set open and permissions passwords
htmlToPdfConverter.Document.Security.OpenPassword = textBoxOpenPassword.Text;
htmlToPdfConverter.Document.Security.PermissionsPassword = textBoxPermissionsPassword.Text;
// Set PDF document permissions
htmlToPdfConverter.Document.Security.AllowPrinting = checkBoxAllowPrint.Checked;
htmlToPdfConverter.Document.Security.AllowCopyContent = checkBoxAllowCopy.Checked;
htmlToPdfConverter.Document.Security.AllowEditContent = checkBoxAllowEdit.Checked;
htmlToPdfConverter.Document.Security.AllowEditAnnotations = checkBoxAllowEditAnnotations.Checked;
htmlToPdfConverter.Document.Security.AllowFormFilling = checkBoxAllowFillForms.Checked;
// Set default permissions password if necessary
if (htmlToPdfConverter.Document.Security.PermissionsPassword == string.Empty &&
(htmlToPdfConverter.Document.Security.OpenPassword != string.Empty || !IsDefaultPermission(htmlToPdfConverter.Document.Security)))
{
htmlToPdfConverter.Document.Security.PermissionsPassword = "admin";
}// Create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// Set encryption mode and level
htmlToPdfConverter.Document.Security.EncryptionMode = GetSelectedEncryptionMode();
htmlToPdfConverter.Document.Security.EncryptionLevel = GetSelectedEncryptionLevel();
// Set open and permissions passwords
htmlToPdfConverter.Document.Security.OpenPassword = textBoxOpenPassword.Text;
htmlToPdfConverter.Document.Security.PermissionsPassword = textBoxPermissionsPassword.Text;
// Set PDF document permissions
htmlToPdfConverter.Document.Security.AllowPrinting = checkBoxAllowPrint.Checked;
htmlToPdfConverter.Document.Security.AllowCopyContent = checkBoxAllowCopy.Checked;
htmlToPdfConverter.Document.Security.AllowEditContent = checkBoxAllowEdit.Checked;
htmlToPdfConverter.Document.Security.AllowEditAnnotations = checkBoxAllowEditAnnotations.Checked;
htmlToPdfConverter.Document.Security.AllowFormFilling = checkBoxAllowFillForms.Checked;
// Set default permissions password if necessary
if (htmlToPdfConverter.Document.Security.PermissionsPassword == string.Empty &&
(htmlToPdfConverter.Document.Security.OpenPassword != string.Empty || !IsDefaultPermission(htmlToPdfConverter.Document.Security)))
{
htmlToPdfConverter.Document.Security.PermissionsPassword = "admin";
}' Create the HTML to PDF converter
Dim htmlToPdfConverter As New HtmlToPdf()
' Set encryption mode and level
htmlToPdfConverter.Document.Security.EncryptionMode = GetSelectedEncryptionMode()
htmlToPdfConverter.Document.Security.EncryptionLevel = GetSelectedEncryptionLevel()
' Set open and permissions passwords
htmlToPdfConverter.Document.Security.OpenPassword = textBoxOpenPassword.Text
htmlToPdfConverter.Document.Security.PermissionsPassword = textBoxPermissionsPassword.Text
' Set PDF document permissions
htmlToPdfConverter.Document.Security.AllowPrinting = checkBoxAllowPrint.Checked
htmlToPdfConverter.Document.Security.AllowCopyContent = checkBoxAllowCopy.Checked
htmlToPdfConverter.Document.Security.AllowEditContent = checkBoxAllowEdit.Checked
htmlToPdfConverter.Document.Security.AllowEditAnnotations = checkBoxAllowEditAnnotations.Checked
htmlToPdfConverter.Document.Security.AllowFormFilling = checkBoxAllowFillForms.Checked
' Set default permissions password if necessary
If htmlToPdfConverter.Document.Security.PermissionsPassword = String.Empty AndAlso (htmlToPdfConverter.Document.Security.OpenPassword <> String.Empty OrElse Not IsDefaultPermission(htmlToPdfConverter.Document.Security)) Then
htmlToPdfConverter.Document.Security.PermissionsPassword = "admin"
End If談到 加密 PDF 文件,IronPDF 利用其 API 提供了直接的方法。 開發人員可以移除現有的密碼、設定新的安全性設定、限制使用者的動作,例如註解、複製貼上和表單資料輸入,並將文件設定為唯讀。 IronPDF 允許修改元資料、密碼保護以及精細控制列印權限。
HiQPdf 也提供 PDF 加密功能,但流程略有不同,著重於設定加密模式、層級、開啟密碼和權限密碼。 它允許對文件權限(如列印、內容複製和編輯)進行細粒度控制,在未明確設定時可使用預設權限。 這兩個函式庫都提供了全面的安全性設定,但 IronPDF 提供了額外的功能,如元資料自訂和更容易處理文件的唯讀模式。
重制 PDF 文件內容
IronPDF範例:
using IronPdf;
// Load an existing PDF
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact specific text
pdf.RedactTextOnAllPages("are");
// Save the updated PDF
pdf.SaveAs("redacted.pdf");using IronPdf;
// Load an existing PDF
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact specific text
pdf.RedactTextOnAllPages("are");
// Save the updated PDF
pdf.SaveAs("redacted.pdf");Imports IronPdf
' Load an existing PDF
Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")
' Redact specific text
pdf.RedactTextOnAllPages("are")
' Save the updated PDF
pdf.SaveAs("redacted.pdf")HiQPdf 並未在其列出的功能中提供明確的編輯功能。 主要著重於 PDF 的產生、轉換和處理,例如從 HTML 建立 PDF。
IronPdf 提供了一種簡單直接的方法從您的 PDF 文件頁面中刪除內容。 舉例來說,開發人員只需幾行程式碼,就能輕鬆地刪除整個文件中的特定文字,如上述程式碼片段所示。 相較之下,HiQPdf 的功能集中缺乏明確的編輯功能,主要著重於 PDF 的產生、轉換和處理,例如從 HTML 建立 PDF。
數位簽章 PDF 檔案
IronPDF範例:
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");
// Load a digital certificate and sign the PDF
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);
var sig = new PdfSignature(cert);
pdf.Sign(sig);
// Save the signed PDF
pdf.SaveAs("signed.pdf");using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");
// Load a digital certificate and sign the PDF
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);
var sig = new PdfSignature(cert);
pdf.Sign(sig);
// Save the signed PDF
pdf.SaveAs("signed.pdf");Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates
' Create a PDF from HTML
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>foo</h1>")
' Load a digital certificate and sign the PDF
Private cert As New X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable)
Private sig = New PdfSignature(cert)
pdf.Sign(sig)
' Save the signed PDF
pdf.SaveAs("signed.pdf")HiQPdf:
// Create a PDF document
PdfDocument document = new PdfDocument();
// Add a page to the document
PdfPage page1 = document.AddPage();
// Create fonts for text
Font sysFont = new Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
PdfFont pdfFontEmbed = document.CreateFont(sysFont, true);
// Add a title to the PDF document
PdfText titleTextTransImage = new PdfText(5, 20, "Click the image below to open the digital signature", pdfFontEmbed);
titleTextTransImage.ForeColor = Color.Navy;
PdfLayoutInfo textLayoutInfo = page1.Layout(titleTextTransImage);
// Layout a PNG image with alpha transparency
PdfImage transparentPdfImage = new PdfImage(5, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
PdfLayoutInfo imageLayoutInfo = page1.Layout(transparentPdfImage);
// Apply digital signature
PdfCertificatesCollection pdfCertificates = PdfCertificatesCollection.FromFile(Server.MapPath("~") + @"\DemoFiles\Pfx\hiqpdf.pfx", "hiqpdf");
PdfDigitalSignature digitalSignature = new PdfDigitalSignature(pdfCertificates[0]);
digitalSignature.SigningReason = "My signing reason";
digitalSignature.SigningLocation = "My signing location";
digitalSignature.SignerContactInfo = "My contact info";
document.AddDigitalSignature(digitalSignature, imageLayoutInfo.LastPdfPage, imageLayoutInfo.LastPageRectangle);
try
{
// Write the PDF document to a memory buffer
byte[] pdfBuffer = document.WriteToMemory();
// Inform the browser about the binary data format
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
// Let the browser know how to open the PDF document and the file name
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=DigitalSignatures.pdf; size={0}",
pdfBuffer.Length.ToString()));
// Write the PDF buffer to HTTP response
HttpContext.Current.Response.BinaryWrite(pdfBuffer);
// End the HTTP response
HttpContext.Current.Response.End();
}
finally
{
document.Close();
}// Create a PDF document
PdfDocument document = new PdfDocument();
// Add a page to the document
PdfPage page1 = document.AddPage();
// Create fonts for text
Font sysFont = new Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
PdfFont pdfFontEmbed = document.CreateFont(sysFont, true);
// Add a title to the PDF document
PdfText titleTextTransImage = new PdfText(5, 20, "Click the image below to open the digital signature", pdfFontEmbed);
titleTextTransImage.ForeColor = Color.Navy;
PdfLayoutInfo textLayoutInfo = page1.Layout(titleTextTransImage);
// Layout a PNG image with alpha transparency
PdfImage transparentPdfImage = new PdfImage(5, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
PdfLayoutInfo imageLayoutInfo = page1.Layout(transparentPdfImage);
// Apply digital signature
PdfCertificatesCollection pdfCertificates = PdfCertificatesCollection.FromFile(Server.MapPath("~") + @"\DemoFiles\Pfx\hiqpdf.pfx", "hiqpdf");
PdfDigitalSignature digitalSignature = new PdfDigitalSignature(pdfCertificates[0]);
digitalSignature.SigningReason = "My signing reason";
digitalSignature.SigningLocation = "My signing location";
digitalSignature.SignerContactInfo = "My contact info";
document.AddDigitalSignature(digitalSignature, imageLayoutInfo.LastPdfPage, imageLayoutInfo.LastPageRectangle);
try
{
// Write the PDF document to a memory buffer
byte[] pdfBuffer = document.WriteToMemory();
// Inform the browser about the binary data format
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
// Let the browser know how to open the PDF document and the file name
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=DigitalSignatures.pdf; size={0}",
pdfBuffer.Length.ToString()));
// Write the PDF buffer to HTTP response
HttpContext.Current.Response.BinaryWrite(pdfBuffer);
// End the HTTP response
HttpContext.Current.Response.End();
}
finally
{
document.Close();
}' Create a PDF document
Dim document As New PdfDocument()
' Add a page to the document
Dim page1 As PdfPage = document.AddPage()
' Create fonts for text
Dim sysFont As New Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point)
Dim pdfFontEmbed As PdfFont = document.CreateFont(sysFont, True)
' Add a title to the PDF document
Dim titleTextTransImage As New PdfText(5, 20, "Click the image below to open the digital signature", pdfFontEmbed)
titleTextTransImage.ForeColor = Color.Navy
Dim textLayoutInfo As PdfLayoutInfo = page1.Layout(titleTextTransImage)
' Layout a PNG image with alpha transparency
Dim transparentPdfImage As New PdfImage(5, 50, Server.MapPath("~") & "\DemoFiles\Images\HiQPdfLogo_small.png")
Dim imageLayoutInfo As PdfLayoutInfo = page1.Layout(transparentPdfImage)
' Apply digital signature
Dim pdfCertificates As PdfCertificatesCollection = PdfCertificatesCollection.FromFile(Server.MapPath("~") & "\DemoFiles\Pfx\hiqpdf.pfx", "hiqpdf")
Dim digitalSignature As New PdfDigitalSignature(pdfCertificates(0))
digitalSignature.SigningReason = "My signing reason"
digitalSignature.SigningLocation = "My signing location"
digitalSignature.SignerContactInfo = "My contact info"
document.AddDigitalSignature(digitalSignature, imageLayoutInfo.LastPdfPage, imageLayoutInfo.LastPageRectangle)
Try
' Write the PDF document to a memory buffer
Dim pdfBuffer() As Byte = document.WriteToMemory()
' Inform the browser about the binary data format
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf")
' Let the browser know how to open the PDF document and the file name
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=DigitalSignatures.pdf; size={0}", pdfBuffer.Length.ToString()))
' Write the PDF buffer to HTTP response
HttpContext.Current.Response.BinaryWrite(pdfBuffer)
' End the HTTP response
HttpContext.Current.Response.End()
Finally
document.Close()
End Try在數位簽章PDF 檔案中,IronPDF 提供了一種直接的方法,它允許開發人員從 HTML 內容建立 PDF 文件,使用數位憑證簽章,然後以最少的程式碼儲存。 另一方面,HiQPdf 需要更複雜的設定,透過新增頁面和嵌入字體,以程式化的方式建立 PDF 文件。 包括標題和圖片,接著使用指定的憑證應用數位簽章,以及詳細的元資料,例如簽章原因和位置。
套用自訂水印
IronPDF範例:
using IronPdf;
// Create a PDF renderer and render URL
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Apply a watermark to the PDF
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
// Save the PDF
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");using IronPdf;
// Create a PDF renderer and render URL
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Apply a watermark to the PDF
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
// Save the PDF
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");Imports IronPdf
' Create a PDF renderer and render URL
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
' Apply a watermark to the PDF
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
' Save the PDF
pdf.SaveAs("C:\Path\To\Watermarked.pdf")HiQPdf:
無內建專用水印工具。
應用自訂水印時,IronPDF 提供了直接的解決方案,內建支援將水印新增至 PDF。 在範例中,URL 會呈現為 PDF,並在頁面中央套用具有 HTML 風格的自訂水印。 這樣可以輕鬆修改水印的內容、樣式和位置。 相較之下,HiQPdf 缺乏內建的專用水印工具,因此對於需要直接在函式庫中使用此功能的開發人員而言較不方便。
將圖片和文字印製到 PDF 中
IronPDF 示例(文本印章):
using IronPdf;
using IronPdf.Editing;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create and apply a text stamp
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top
};
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");using IronPdf;
using IronPdf.Editing;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create and apply a text stamp
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top
};
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");Imports IronPdf
Imports IronPdf.Editing
' Create a PDF from HTML
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create and apply a text stamp
Private textStamper As New TextStamper() With {
.Text = "Text Stamper!",
.FontFamily = "Bungee Spice",
.UseGoogleFont = True,
.FontSize = 30,
.IsBold = True,
.IsItalic = True,
.VerticalAlignment = VerticalAlignment.Top
}
pdf.ApplyStamp(textStamper)
pdf.SaveAs("stampText.pdf")IronPDF 示例(圖章):
using IronPdf;
using IronPdf.Editing;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create and apply an image stamp
ImageStamper imageStamper = new ImageStamper(new Uri("/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top
};
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");using IronPdf;
using IronPdf.Editing;
// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create and apply an image stamp
ImageStamper imageStamper = new ImageStamper(new Uri("/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top
};
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");Imports IronPdf
Imports IronPdf.Editing
' Create a PDF from HTML
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create and apply an image stamp
Private imageStamper As New ImageStamper(New Uri("/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}
pdf.ApplyStamp(imageStamper, 0)
pdf.SaveAs("stampImage.pdf")HiQPdf:
HiQPdf 沒有專用的圖章工具,無法直接將文字或圖片加入 PDF 文件中作為圖章。 然而,它允許您在 PDF 中加入文字、圖片和圖形物件,可以達到類似目的。 這可以透過使用資料庫中的可用功能在 PDF 中建立文字物件和影像物件來完成。
IronPDF 提供了專門的類別,可直接在任何現有的 PDF 文件或新建立的 PDF 文件上標示文字和影像,讓開發人員可以直接進行處理。 相較之下,HiQPdf 則缺乏專用的戳記工具; 反之,它允許使用者在 PDF 內新增文字和圖像物件,需要更多的手動方式才能達到類似效果。
DOCX 至 PDF 轉換
IronPDF範例:
using IronPdf;
// Render DOCX to PDF
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the converted PDF
pdf.SaveAs("pdfFromDocx.pdf");using IronPdf;
// Render DOCX to PDF
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the converted PDF
pdf.SaveAs("pdfFromDocx.pdf");Imports IronPdf
' Render DOCX to PDF
Private renderer As New DocxToPdfRenderer()
Private pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the converted PDF
pdf.SaveAs("pdfFromDocx.pdf")HiQPdf:
由於 HiQPdf 主要是 HTML 至 PDF 的轉換函式庫,因此不提供任何內建 DOCX 至 PDF 的工具。
IronPDF 透過其 DocxToPdfRenderer 類提供 DOCX 至 PDF 轉換的直接支援,而 HiQPdf 則缺乏將 DOCX 檔案轉換為 PDF 的內建工具,而是專注於 HTML 至 PDF 的轉換。
程式碼範例比較摘要

若要進一步瞭解 IronPDF 所提供的豐富功能,並觀看它們的實際應用,請查看 IronPDF 使用指南,這些指南會深入介紹每項功能,探討它們如何運作,並提供您成為 PDF 專業人士所需的技能。
現代 CSS 框架和 Bootstrap 渲染。
由於現代網路應用程式越來越多採用 CSS 架構(例如 Bootstrap)來進行快速開發和一致的 UI 設計,因此 PDF 生成函式庫必須準確保留這些架構佈局,以維持專業品質。
IronPdf:完整的 Bootstrap 和 Framework 支援。
IronPDF 的 Chromium 渲染引擎提供了對所有現代 CSS 框架的全面支援:
- Bootstrap 5:完整的 flexbox 與 CSS Grid,具備所有回應式工具
- Bootstrap 4:完整的卡片系統、導覽和表單元件
- Tailwind CSS:所有實用類別與反應式修改器
- 基礎:完整的網格和元件系統
- 現代 CSS3:Flexbox、網格、自訂屬性、動畫、變形
以生產實例進行驗證:Bootstrap首頁和Bootstrap範本的轉換精確到像素。
程式碼範例:使用 Bootstrap 的部落格文章清單
using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapBlog = @"
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Latest Blog Posts</h1>
<article class='card mb-4 shadow-sm'>
<div class='row g-0'>
<div class='col-md-4'>
<img src='https://via.placeholder.com/400x300' class='img-fluid rounded-start' alt='Blog post'>
</div>
<div class='col-md-8'>
<div class='card-body d-flex flex-column h-100'>
<div class='d-flex justify-content-between align-items-center mb-2'>
<span class='badge bg-primary'>Technology</span>
<small class='text-muted'>March 15, 2025</small>
</div>
<h2 class='card-title h4'>The Future of Web Development</h2>
<p class='card-text flex-grow-1'>Exploring emerging trends in web development including serverless architecture, edge computing, and the evolution of JavaScript frameworks...</p>
<div class='mt-auto'>
<a href='#' class='btn btn-outline-primary'>Read More</a>
</div>
</div>
</div>
</div>
</article>
<article class='card mb-4 shadow-sm'>
<div class='row g-0'>
<div class='col-md-4'>
<img src='https://via.placeholder.com/400x300' class='img-fluid rounded-start' alt='Blog post'>
</div>
<div class='col-md-8'>
<div class='card-body d-flex flex-column h-100'>
<div class='d-flex justify-content-between align-items-center mb-2'>
<span class='badge bg-success'>Tutorial</span>
<small class='text-muted'>March 10, 2025</small>
</div>
<h2 class='card-title h4'>Mastering Docker Containerization</h2>
<p class='card-text flex-grow-1'>A comprehensive guide to Docker containerization, from basics to advanced deployment strategies for production environments...</p>
<div class='mt-auto'>
<a href='#' class='btn btn-outline-primary'>Read More</a>
</div>
</div>
</div>
</div>
</article>
<nav aria-label='Blog pagination'>
<ul class='pagination justify-content-center'>
<li class='page-item disabled'>
<a class='page-link'>Previous</a>
</li>
<li class='page-item active'><a class='page-link' href='#'>1</a></li>
<li class='page-item'><a class='page-link' href='#'>2</a></li>
<li class='page-item'><a class='page-link' href='#'>3</a></li>
<li class='page-item'>
<a class='page-link' href='#'>Next</a>
</li>
</ul>
</nav>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapBlog);
pdf.SaveAs("blog-posts.pdf");using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapBlog = @"
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Latest Blog Posts</h1>
<article class='card mb-4 shadow-sm'>
<div class='row g-0'>
<div class='col-md-4'>
<img src='https://via.placeholder.com/400x300' class='img-fluid rounded-start' alt='Blog post'>
</div>
<div class='col-md-8'>
<div class='card-body d-flex flex-column h-100'>
<div class='d-flex justify-content-between align-items-center mb-2'>
<span class='badge bg-primary'>Technology</span>
<small class='text-muted'>March 15, 2025</small>
</div>
<h2 class='card-title h4'>The Future of Web Development</h2>
<p class='card-text flex-grow-1'>Exploring emerging trends in web development including serverless architecture, edge computing, and the evolution of JavaScript frameworks...</p>
<div class='mt-auto'>
<a href='#' class='btn btn-outline-primary'>Read More</a>
</div>
</div>
</div>
</div>
</article>
<article class='card mb-4 shadow-sm'>
<div class='row g-0'>
<div class='col-md-4'>
<img src='https://via.placeholder.com/400x300' class='img-fluid rounded-start' alt='Blog post'>
</div>
<div class='col-md-8'>
<div class='card-body d-flex flex-column h-100'>
<div class='d-flex justify-content-between align-items-center mb-2'>
<span class='badge bg-success'>Tutorial</span>
<small class='text-muted'>March 10, 2025</small>
</div>
<h2 class='card-title h4'>Mastering Docker Containerization</h2>
<p class='card-text flex-grow-1'>A comprehensive guide to Docker containerization, from basics to advanced deployment strategies for production environments...</p>
<div class='mt-auto'>
<a href='#' class='btn btn-outline-primary'>Read More</a>
</div>
</div>
</div>
</div>
</article>
<nav aria-label='Blog pagination'>
<ul class='pagination justify-content-center'>
<li class='page-item disabled'>
<a class='page-link'>Previous</a>
</li>
<li class='page-item active'><a class='page-link' href='#'>1</a></li>
<li class='page-item'><a class='page-link' href='#'>2</a></li>
<li class='page-item'><a class='page-link' href='#'>3</a></li>
<li class='page-item'>
<a class='page-link' href='#'>Next</a>
</li>
</ul>
</nav>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapBlog);
pdf.SaveAs("blog-posts.pdf");IRON VB CONVERTER ERROR developers@ironsoftware.com輸出:一個專業的部落格清單,包含 Bootstrap 的卡片式版面、flexbox 對齊方式、徽章元件和分頁方式,所有這些都能精確地呈現在 PDF 中。
HiQPdf:有限的現代框架支援
HiQPdf 使用基於 WebKit 的 HTML 渲染,對於現代 CSS 框架有很大的限制:
- WebKit 引擎:較舊的 WebKit 版本,對 CSS3 的支援不完整
- Limited Flexbox:Bootstrap 4/5 flexbox 布局可能無法正確呈現
- No CSS Grid:不支援現代網格系統
- Bootstrap 3 限制:只有較舊的以表格為基礎的 Bootstrap 版本才能穩定運作
- JavaScript 的限制:與現代瀏覽器相比,JavaScript 執行能力降低
開發人員報告的 HiQPdf 問題:
- Bootstrap 導覽元件呈現對齊問題
- 基於 Flexbox 的卡片佈局無法正確顯示
- PDF 輸出中忽略了回應式公用程式和突破點
- 複雜的 Bootstrap 元件需要大量的 CSS 變通程式
開發影響:使用 Bootstrap 4+ 的應用程式需要使用 HiQPdf 進行大量的額外工作。 團隊必須維護平行簡化的 CSS 以產生 PDF(雙重維護負擔),將 UI 限制為 Bootstrap 3(犧牲現代功能),或是廣泛測試並手動修正元件(費時且脆弱)。
如需全面的 Bootstrap 相容性指南,請參閱 Bootstrap & Flexbox CSS 指南。
文件和支援:IronPDF vs. HiQPdf
IronPDF 文件和支援。
IronPdf 提供開發人員友善的文件體驗。 其強大的說明文件可確保開發人員,無論是初學者或進階使用者,都能有效地將 IronPDF 整合至其專案中。 IronPdf 文件的一些關鍵方面包括
- Step-by-Step Guides:每項功能的全面教學,確保開發人員從開始到完成都有明確的路徑。
- 24/5技術支援:工程師可在週一至週五的工作時間內協助處理任何疑問或問題。
- 即時聊天:即時支援以解決授權或技術問題。
- 電子郵件支援:使用者可透過電子郵件提出詳細的諮詢,且回覆迅速且提供協助。
- API Reference:詳盡的 API 文件,包含每個方法和屬性的範例。
- 程式碼範例:適用於 HTML 轉 PDF、加密、水印等常見工作的即用程式碼片段。
- 定期更新:經常更新文件,以反映程式庫的變更和新功能。
如需更多資訊,請參閱 IronPdf 廣泛的 說明文件,並請造訪 Iron Software YouTube 頻道。
HiQPdf 文件和支援
HiQPdf 提供基本的文件,支援其大部分的核心功能。 雖然它提供 HTML 至 PDF 轉換和基本 PDF 操作的功能,但文件缺乏 IronPDF 所提供的深度和全面性。 HiQPdf 文件的主要方面包括
- Basic API Reference:列出 HTML 轉 PDF 和基本 PDF 操作的方法。
- 程式碼範例:HTML 至 PDF 轉換和頁面設定的有限範例程式碼。
- 最低限度的跨平台指導:主要著重於 Windows 環境,對跨平台部署的指導較少。
- 電子郵件支援:主要用於授權和基本技術查詢。
- 有限的即時支援:實時協助的選項較少。
如需更多關於 HiQPdf 的技術細節,使用者需透過其他資源或外部論壇搜尋。
定價與授權:IronPDF vs. HiQPdf
IronPDF 定價與授權
IronPDF有不同的購買授權等級和附加功能。 開發人員也可以購買 Iron Suite,以兩件產品的價格即可使用 Iron Software 的所有產品。 如果您尚未準備好購買授權,IronPDF 提供 免費試用,讓您可以在承諾購買授權之前探索它的所有功能。
定價(截至 2025 年):
- 永久授權:提供一系列永久授權,視您的團隊規模、專案需求,以及每種授權類型隨附電子郵件支援的地點數量而定。
- Lite License:此授權費用為 $799 並支援一位開發人員、一個地點和一個專案。
- Plus License: 支援三位開發人員、三個地點和三個專案,這是 Lite License 的進階版本,費用為 $1,199。 Plus License 除了提供基本的電子郵件支援外,還提供聊天支援和電話支援。
- Professional License:此 License 適合較大型的團隊,可支援十位開發人員、十個地點和十個專案,費用為 $2,399 。 它提供與前幾層相同的聯絡支援管道,但也提供螢幕分享支援。
- 免版稅再發行: IronPDF 的授權也提供免版稅再發行的保障,只需額外支付 $2,399 的費用。
- 不間斷的產品支援: IronPdf 提供持續的產品更新、安全功能升級,以及工程團隊的支援,費用為 999 美元/年或一次性購買 5 年保障的 1,999 美元。
- Iron Suite:只需 $1,498 即可使用所有 Iron Software 產品,包括 IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint和IronWebScraper。

HiQPdf 定價與授權
HiQPdf 也提供多種授權選項,但其定價往往略為僵化:
- Startup License: 單一開發人員與單一應用程式的費用為 245 美元
- 開發人員授權:一個開發人員可使用任何數量的應用程式,費用為 495 美元。
- Team License: $795,最多可供五名開發人員使用,他們可在任何數量的應用程式上工作。
- Enterprise License:1,095 美元,適用於不限數量的開發人員與任意數量的應用程式。
雖然 HiQPdf 的價格很有競爭力,但它提供的價值不如 IronPDF 透過 Iron Suite 提供的捆綁式服務,也不如價格中包含的進階功能廣泛。
結論
IronPDF 和 HiQPdf 都是 .NET 開發人員希望將 PDF 功能整合到其應用程式中的可靠選擇。 然而,IronPDF 以其廣泛的功能集、易用性和強大的說明文件而大放異彩。 IronPDF 具備跨平台相容性、豐富的程式碼範例以及優異的支援,對於需要在不同環境下使用全面 PDF 功能的開發人員而言,IronPDF 是絕佳的解決方案。
如果您正在尋找一個完整的解決方案,並能提供優異的效能、彈性和支援,IronPDF是非常值得推薦的選擇。此外,IronPDF 能輕鬆處理加密、編輯和數位簽署等進階功能,這讓它在 HiQPdf 中脫穎而出。
常見問題解答
如何在 C# 中將 HTML 轉換為 PDF?
您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字串轉換成 PDF。您也可以使用 RenderHtmlFileAsPdf 將 HTML 檔案轉換成 PDF。
IronPDF 支援哪些平台?
IronPDF for .NET 兼容 Windows、Linux、macOS、Docker、Azure、AWS 和主要 .NET 版本,包括 .NET 8、7、6 和 .NET Core。
我可以在 C# 中對 PDF 應用數位簽章嗎?
是的,IronPDF 允許您使用其 API 對 PDF 文件應用數位簽章。您可以指定憑證和元資料(如簽署原因和位置)。
如何在 PDF 文件中加入水印?
IronPDF 內建支援為 PDF 新增自訂水印。您可以使用 IronPDF 的 API 輕鬆地將水印整合到 PDF 文件中。
IronPDF 提供哪些安全功能?
IronPDF 提供先進的安全功能,包括加密、密碼保護、權限設定,以及讓文件唯讀的功能。
IronPDF 是否支援 DOCX 至 PDF 的轉換?
是的,IronPDF 支援 DOCX 至 PDF 的轉換。您可以使用 DocxToPdfRenderer 類將 DOCX 文件無縫轉換為 PDF。
IronPDF 如何處理 HTML 到 PDF 的轉換?
IronPDF 使用 ChromePdfRenderer 將 HTML 內容渲染為 PDF,支援 HTML 文件、字串、URL 以及具有本機資產(如圖片)的情境。
IronPDF 提供哪些支援和文件?
IronPDF 提供全面的文件,包括分步指南、廣泛的 API 參考資料和程式碼範例。它還透過即時聊天和電子郵件提供 24/5 技術支援。
IronPDF 可以用於編輯 PDF 文件中的內容嗎?
是的,IronPDF 提供了一種直接的方法,可在整個 PDF 文件中刪除特定文字,讓開發人員有效地管理敏感資訊。
IronPDF 有哪些類型的授權?
IronPDF 提供多種授權,包括 Lite、Plus、Professional,以及可使用所有 Iron Software 產品的 Iron Suite。它也提供免版稅的再散佈選項。







