RawPrint .NET vs IronPDF:技術比較指南
當.NET開發人員評估文件列印和 PDF 產生解決方案時,RawPrint .NET和IronPDF提供了截然不同的方法和功能。 RawPrint .NET提供對印表機後台處理程序的底層訪問,以便直接向印表機發送原始字節,而IronPDF提供完整的高級 API,用於建立、操作和列印 PDF 文件。 本次技術比較從專業開發人員和架構師在為.NET應用程式做出文件處理決策時最關心的幾個方面對兩種解決方案進行了考察。
了解.NET
RawPrint .NET是一個底層列印實用程序,它直接向印表機後台處理程序傳送原始位元組。 它使應用程式能夠繞過傳統的印表機驅動程序,直接向印表機傳輸命令資料。 此功能對於使用 ZPL(斑馬程式語言)或 EPL(艾爾創程式語言)的標籤印表機等專用印表機尤其有用。
關鍵差異: RawPrint .NET不是一個 PDF 函式庫。 它不會建立、產生、渲染或操作 PDF 文件。 它的唯一功能是透過 視窗 列印子系統向印表機硬體傳輸位元組。
此方法要求開發人員使用來自 winspool.Drv 的 視窗 特定 DLL導入,並透過一系列函數呼叫手動管理印表機句柄:EndPagePrinter、@fCO-2。
RawPrint .NET 的架構需求對印表機指令語言有深入的了解。 對於文件格式設置,開發人員必須手動建立 PCL(印表機命令語言)或 PostScript 命令,作為嵌入位元組流中的轉義序列。
了解IronPDF
IronPDF為.NET應用程式中的 PDF 操作提供了一個完整的進階 API。 該程式庫包含一個基於 Chromium 的渲染引擎,可以將 HTML、CSS 和JavaScript完全保真地轉換為 PDF 文件。 除了產生功能外, IronPDF還提供 PDF 操作功能,包括合併、分割、編輯和安全功能。
IronPDF 的架構抽象化了文件渲染和印表機通訊的複雜性。 ChromePdfRenderer 類別處理 HTML 到 PDF 的轉換,而 PdfDocument 類別提供無需手動資源管理即可進行操作和列印的方法。
核心能力差距
RawPrint .NET和IronPDF的根本差異在於它們的用途和功能:
| 任務 | .NET | IronPDF |
|---|---|---|
| 從 HTML 建立 PDF | 不支援。 | 是的 |
| 從 URL 建立 PDF | 不支援。 | 是的 |
| 編輯/修改PDF | 不支援。 | 是的 |
| 合併/拆分PDF | 不支援。 | 是的 |
| 列印現有PDF | 是的(僅原始位元組) | 是的(進階 API) |
| 列印控制 | 基本的 | 全部選項 |
| 跨平台 | 僅限 視窗 系統 | 是的 |
透過比較可以發現,RawPrint .NET和IronPDF服務於完全不同的使用情境。 RawPrint .NET解決底層印表機通訊問題,而IronPDF提供完整的 PDF 文件生命週期管理。
HTML 轉 PDF
在考察 HTML 到 PDF 的轉換場景時,RawPrint .NET和IronPDF之間的對比就顯得非常明顯了。
.NET HTML 處理
.NET無法將 HTML 轉換為 PDF。 它只能向印表機發送原始資料:
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Text;
class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)] public string pDocName;
[MarshalAs(UnmanagedType.LPStr)] public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)] public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);
[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
public static bool SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
IntPtr hPrinter;
if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
{
DOCINFOA di = new DOCINFOA();
di.pDocName = "HTML Document";
di.pDataType = "RAW";
if (StartDocPrinter(hPrinter, 1, di))
{
if (StartPagePrinter(hPrinter))
{
Int32 dwWritten;
WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
Marshal.FreeCoTaskMem(pBytes);
return true;
}
return false;
}
}
class Program
{
static void Main()
{
string html = "<html><body><h1>Hello World</h1></body></html>";
// RawPrint cannot directly convert HTML to PDF
// It sends raw data to printer, no PDF generation capability
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", html);
}
}
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Text;
class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)] public string pDocName;
[MarshalAs(UnmanagedType.LPStr)] public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)] public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);
[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
public static bool SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
IntPtr hPrinter;
if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
{
DOCINFOA di = new DOCINFOA();
di.pDocName = "HTML Document";
di.pDataType = "RAW";
if (StartDocPrinter(hPrinter, 1, di))
{
if (StartPagePrinter(hPrinter))
{
Int32 dwWritten;
WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
Marshal.FreeCoTaskMem(pBytes);
return true;
}
return false;
}
}
class Program
{
static void Main()
{
string html = "<html><body><h1>Hello World</h1></body></html>";
// RawPrint cannot directly convert HTML to PDF
// It sends raw data to printer, no PDF generation capability
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", html);
}
}
Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Imports System.Text
Class RawPrinterHelper
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
Public Class DOCINFOA
<MarshalAs(UnmanagedType.LPStr)> Public pDocName As String
<MarshalAs(UnmanagedType.LPStr)> Public pOutputFile As String
<MarshalAs(UnmanagedType.LPStr)> Public pDataType As String
End Class
<DllImport("winspool.Drv", EntryPoint:="OpenPrinterA", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function OpenPrinter(<MarshalAs(UnmanagedType.LPStr)> szPrinter As String, ByRef hPrinter As IntPtr, pd As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="ClosePrinter", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function ClosePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartDocPrinterA", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function StartDocPrinter(hPrinter As IntPtr, level As Integer, <[In], MarshalAs(UnmanagedType.LPStruct)> di As DOCINFOA) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="WritePrinter", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Shared Function WritePrinter(hPrinter As IntPtr, pBytes As IntPtr, dwCount As Integer, ByRef dwWritten As Integer) As Boolean
End Function
Public Shared Function SendStringToPrinter(szPrinterName As String, szString As String) As Boolean
Dim pBytes As IntPtr
Dim dwCount As Integer
dwCount = szString.Length
pBytes = Marshal.StringToCoTaskMemAnsi(szString)
Dim hPrinter As IntPtr
If OpenPrinter(szPrinterName, hPrinter, IntPtr.Zero) Then
Dim di As New DOCINFOA()
di.pDocName = "HTML Document"
di.pDataType = "RAW"
If StartDocPrinter(hPrinter, 1, di) Then
If StartPagePrinter(hPrinter) Then
Dim dwWritten As Integer
WritePrinter(hPrinter, pBytes, dwCount, dwWritten)
EndPagePrinter(hPrinter)
End If
EndDocPrinter(hPrinter)
End If
ClosePrinter(hPrinter)
Marshal.FreeCoTaskMem(pBytes)
Return True
End If
Return False
End Function
End Class
Class Program
Shared Sub Main()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
' RawPrint cannot directly convert HTML to PDF
' It sends raw data to printer, no PDF generation capability
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", html)
End Sub
End Class
這段程式碼示範了 .NET 的限制:它將原始 HTML 字串傳送到印表機,而不是將其呈現為格式化的文件。 輸出結果將是純 HTML 標記文本,而不是渲染後的網頁。
IronPDF HTML 轉換
IronPDF提供完整的 HTML 到 PDF 轉換和渲染功能:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully")
End Sub
End Class
IronPDF方法使用RenderHtmlAsPdf方法將 HTML 內容轉換為正確渲染的 PDF 文件。 Chromium 引擎處理 CSS、 JavaScript和 HTML,以產生與瀏覽器渲染相符的輸出。
URL 轉 PDF
將即時網頁轉換為 PDF 進一步說明了兩者的功能差異。
.NET URL 處理
.NET無法渲染網頁,它只能傳輸原始資料:
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
static void Main()
{
// RawPrint cannot render web pages - only sends raw text/data
// This would just print HTML source code, not rendered content
using (WebClient client = new WebClient())
{
string htmlSource = client.DownloadString("https://example.com");
// This prints raw HTML, not a rendered PDF
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", htmlSource);
Console.WriteLine("Raw HTML sent to printer (not rendered)");
}
}
}
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
static void Main()
{
// RawPrint cannot render web pages - only sends raw text/data
// This would just print HTML source code, not rendered content
using (WebClient client = new WebClient())
{
string htmlSource = client.DownloadString("https://example.com");
// This prints raw HTML, not a rendered PDF
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", htmlSource);
Console.WriteLine("Raw HTML sent to printer (not rendered)");
}
}
}
Imports System
Imports System.Net
Imports System.Runtime.InteropServices
Imports System.Text
Module Program
Sub Main()
' RawPrint cannot render web pages - only sends raw text/data
' This would just print HTML source code, not rendered content
Using client As New WebClient()
Dim htmlSource As String = client.DownloadString("https://example.com")
' This prints raw HTML, not a rendered PDF
RawPrinterHelper.SendStringToPrinter("Microsoft Print to PDF", htmlSource)
Console.WriteLine("Raw HTML sent to printer (not rendered)")
End Using
End Sub
End Module
這種方法會下載 HTML 原始碼,並將其作為原始文字傳送到印表機。 最終產生的是列印出來的 HTML 標記,而不是帶有樣式、圖像或佈局的渲染網頁。
IronPDF URL轉換
IronPDF可將即時網站直接渲染成 PDF:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Render a live website directly to PDF with full CSS, JavaScript, and images
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Website rendered to PDF successfully");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Render a live website directly to PDF with full CSS, JavaScript, and images
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Website rendered to PDF successfully");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
' Render a live website directly to PDF with full CSS, JavaScript, and images
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("Website rendered to PDF successfully")
End Sub
End Class
RenderUrlAsPdf方法導覽至 URL,執行JavaScript,套用 CSS 樣式,載入圖片,並將完全渲染的頁面擷取為 PDF 文件。
文件格式比較
格式化功能揭示了兩種方法之間的架構差異。
RawPrint .NET格式化
.NET需要手動執行 PCL 或 PostScript 指令才能進行任何格式化操作:
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
static void Main()
{
// RawPrint requires manual PCL/PostScript commands for formatting
string pclCommands = "\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T";
string text = "Plain text document - limited formatting";
byte[] data = Encoding.ASCII.GetBytes(pclCommands + text);
RawPrinterHelper.SendBytesToPrinter("HP LaserJet", data);
}
}
// NuGet: Install-Package System.Drawing.Common
using System;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
static void Main()
{
// RawPrint requires manual PCL/PostScript commands for formatting
string pclCommands = "\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T";
string text = "Plain text document - limited formatting";
byte[] data = Encoding.ASCII.GetBytes(pclCommands + text);
RawPrinterHelper.SendBytesToPrinter("HP LaserJet", data);
}
}
Imports System
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Imports System.Text
Module Program
Sub Main()
' RawPrint requires manual PCL/PostScript commands for formatting
Dim pclCommands As String = ChrW(&H1B) & "&l0O" & ChrW(&H1B) & "(s0p16.66h8.5v0s0b3T"
Dim text As String = "Plain text document - limited formatting"
Dim data As Byte() = Encoding.ASCII.GetBytes(pclCommands & text)
RawPrinterHelper.SendBytesToPrinter("HP LaserJet", data)
End Sub
End Module
轉義序列(\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T)表示用於印表機設定的 PCL 指令。 開發人員必須了解特定於印表機的命令語言,並手動建立格式化指令。
IronPDF格式
IronPDF使用標準的 HTML 和 CSS 來實現豐富的格式設定:
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = @"
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("formatted.pdf");
Console.WriteLine("Formatted PDF created successfully");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = @"
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("formatted.pdf");
Console.WriteLine("Formatted PDF created successfully");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("formatted.pdf")
Console.WriteLine("Formatted PDF created successfully")
End Sub
End Class
IronPDF充分利用了現有的Web開發技能。 開發人員使用熟悉的 HTML 和 CSS 語法,而不是印表機特定的命令語言。 這種方法透過標準網路技術支援複雜的佈局、字體、顏色和圖像。
API對應參考
評估 RawPrint .NET遷移到IronPDF的團隊可以參考以下操作映射:
| .NET | IronPDF |
|---|---|
Printer.SendBytesToPrinter() |
pdf.Print() |
Printer.OpenPrinter() |
不適用 |
Printer.ClosePrinter() |
不適用 |
Printer.StartDocPrinter() |
不適用 |
Printer.WritePrinter() |
不適用 |
Printer.EndDocPrinter() |
不適用 |
| 不適用 | ChromePdfRenderer |
| 不適用 | PdfDocument.Merge() |
| 不適用 | pdf.ApplyWatermark() |
映射結果顯示, IronPDF完全消除了手動印表機管理。 RawPrint .NET中需要明確 open/close/start/end 呼叫的操作由 IronPDF 的高階 API 自動處理。
特徵比較矩陣
| 特徵 | .NET | IronPDF |
|---|---|---|
| PDF 創建 | ||
| HTML 轉 PDF | 不 | 是的 |
| PDF檔案的URL | 不 | 是的 |
| 從零開始創建 | 不 | 是的 |
| PDF 處理 | ||
| 合併PDF | 不 | 是的 |
| 拆分PDF | 不 | 是的 |
| 添加浮水印 | 不 | 是的 |
| 編輯現有內容 | 不 | 是的 |
| 印刷 | ||
| 列印 PDF | 是的(原始資料) | 是的(高等級) |
| 列印對話框 | 不 | 是的 |
| 多份副本 | 有限的 | 是的 |
| DPI 控制 | 不 | 是的 |
| 複式公寓 | 不 | 是的 |
| 平台 | ||
| 視窗 | 是的 | 是的 |
| Linux | 不 | 是的 |
| macOS | 不 | 是的 |
| Docker | 不 | 是的 |
| 其他 | ||
| 安全 | 不 | 是的 |
| 數位簽名 | 不 | 是的 |
| PDF/A | 不 | 是的 |
列印比較
RawPrint .NET確實提供了一項功能——列印現有文件——但其 API 的複雜性卻大相逕庭。
RawPrint .NET列印
using RawPrint;
using System.IO;
byte[] pdfBytes = File.ReadAllBytes("document.pdf");
bool success = Printer.SendBytesToPrinter(
"Brother HL-L2340D",
pdfBytes,
pdfBytes.Length
);
if (!success)
{
throw new Exception("Print failed");
}
using RawPrint;
using System.IO;
byte[] pdfBytes = File.ReadAllBytes("document.pdf");
bool success = Printer.SendBytesToPrinter(
"Brother HL-L2340D",
pdfBytes,
pdfBytes.Length
);
if (!success)
{
throw new Exception("Print failed");
}
Imports RawPrint
Imports System.IO
Dim pdfBytes As Byte() = File.ReadAllBytes("document.pdf")
Dim success As Boolean = Printer.SendBytesToPrinter("Brother HL-L2340D", pdfBytes, pdfBytes.Length)
If Not success Then
Throw New Exception("Print failed")
End If
RawPrint .NET需要將檔案當作位元組讀取,並手動管理成功/失敗狀態。
IronPDF列印
using IronPdf;
var pdf = PdfDocument.FromFile("document.pdf");
// Simple print
pdf.Print();
// Or specify printer
pdf.Print("Brother HL-L2340D");
using IronPdf;
var pdf = PdfDocument.FromFile("document.pdf");
// Simple print
pdf.Print();
// Or specify printer
pdf.Print("Brother HL-L2340D");
Imports IronPdf
Dim pdf = PdfDocument.FromFile("document.pdf")
' Simple print
pdf.Print()
' Or specify printer
pdf.Print("Brother HL-L2340D")
IronPDF提供了一種簡單的列印方法,可以自動處理印表機通訊。 對於進階應用場景, IronPDF支援列印選項,包括份數、DPI 和灰階設定。
團隊考慮 RawPrint .NET遷移時
促使開發團隊評估.NET的替代方案的因素有很多:
當應用程式需要建立 PDF 文件時,PDF 生成要求就成了阻礙因素。 RawPrint .NET無法產生 PDF 檔案-它只能傳送到印表機位元組。 需要將 HTML 轉換為 PDF 或建立文件的團隊必須使用 RawPrint .NET以及其他函式庫。
跨平台部署要求超出了 .NET 的能力範圍。 此函式庫完全依賴 視窗 列印子系統,透過 winspool.Drv DLL 導入。 Linux、macOS 和 Docker 部署需要不同的解決方案。
API的複雜性會增加維護負擔。 與進階 API 相比,使用明確開啟/關閉/開始/結束序列的手動印表機句柄管理會增加程式碼複雜性和出錯的可能性。
有限的印刷控制會影響生產要求。 RawPrint .NET提供基本的位元組傳輸,不提供副本、DPI、雙面列印或列印對話方塊等選項。
優勢與權衡
RawPrint .NET優勢
- 直接存取專用硬體(標籤印表機、ZPL/EPL 設備)的印表機
- 原始位元組傳輸開銷極小
- 適用於基本列印場景的簡單架構
- 除了Windows DLL之外,沒有其他外部相依性
.NET 的局限性
- 不具備建立或產生 PDF 檔案的功能
- 僅支援 視窗 平台 需要手動管理印表機句柄
- 不渲染 HTML 或 URL
- 格式設定有限(需具備 PCL/PostScript 知識)
- 無PDF操作功能
IronPDF 的優勢
- 從 HTML、URL 和程式碼產生完整的 PDF 文件
- 跨平台支援(Windows、Linux、macOS、Docker)
- 進階 API 消除了手動資源管理
- 透過 Chromium 渲染提供完整的 CSS 和JavaScript支持
- PDF 處理(合併、分割、編輯、新增浮水印) -數位簽名和安全功能 專業支援和文檔
IronPDF注意事項
商業許可模式
- Chromium渲染引擎佔用空間
- 專為 PDF 工作流程而設計,而非直接存取印表機
結論
RawPrint .NET和IronPDF在.NET文件處理中扮演著截然不同的角色。 RawPrint .NET提供向印表機後台處理程序發送原始位元組的底層存取權——這對於標籤印表機或需要直接命令傳輸的裝置的特殊列印場景非常有用。 但是,它無法建立、渲染或操作 PDF 文件。
對於需要產生 PDF、HTML 到 PDF 轉換、文件操作或跨平台列印的應用, IronPDF提供了 RawPrint .NET所不具備的全面功能。 進階 API 消除了手動印表機句柄管理,同時增加了合併、分割、安全性和數位簽章等功能。
在評估 RawPrint .NET向IronPDF 的遷移時,團隊應考慮其具體需求。 如果主要需求是建立和處理 PDF 文檔,列印只是次要功能,那麼IronPDF可以滿足整個工作流程的需求。 對於計劃在 2026 年使用.NET 10 和 C# 14 且有跨平台部署要求的團隊來說,IronPDF 的架構比 視窗 專用的 RawPrint .NET方法提供了更合適的基礎。