比較

RawPrint .NET vs IronPDF:技術比較指南

當 .NET 開發人員評估文件列印和 PDF 產生解決方案時,RawPrint .NET 和IronPDF提供了截然不同的方法和功能。RawPrint .NET提供對印表機後台處理程序的底層訪問,以便直接向印表機發送原始字節,而IronPDF提供完整的高級 API,用於建立、操作和列印 PDF 文件。 本技術比較針對對 .NET 應用程式進行文件處理決策的專業開發人員和架構人員最關心的層面,檢視這兩種解決方案。

瞭解 RawPrint .NET

RawPrint .NET 是一種低階列印工具,可直接將原始位元組傳送至印表機 spooler。 它可讓應用程式繞過傳統的印表機驅動程式,直接將指令資料傳輸至印表機。 此功能對於專業印表機特別有用,例如使用 ZPL (Zebra 程式語言) 或 EPL (Eltron 程式語言) 的標籤製造商。

關鍵差異:RawPrint .NET不是一個 PDF 函式庫。 它不會建立、產生、渲染或處理 PDF 文件。 其唯一功能是透過視窗列印子系統,將位元組傳輸至印表機硬體。

該方法要求開發人員使用來自 winspool.Drv 的視窗特定 DLL 匯入,透過一系列函式呼叫手動管理印表機句柄:OpenPrinter, StartDocPrinter, StartPagePrinter, WritePrinter, EndPagePrinter, EndDocPrinter, 和 ClosePrinter.

RawPrint .NET 的架構需求對印表機指令語言有深入的了解。 對於文件格式,開發人員必須以嵌入在位元組串流中的轉換順序來建構手動 PCL(印表機指令語言)或 PostScript 指令。

了解 IronPDF

IronPDF為 .NET 應用程式中的 PDF 操作提供了一個完整的進階 API。 該函式庫包含一個以 Chromium 為基礎的渲染引擎,可將 HTML、CSS 和 JavaScript 完全忠實地轉換成 PDF 文件。 除了生成功能外,IronPDF 還提供 PDF 操作功能,包括合併、分割、編輯和安全功能。

IronPDF 的架構抽象了文件渲染和印表機通訊的複雜性。ChromePdfRenderer類處理 HTML 到 PDF 的轉換,而 PdfDocument 類提供操作和列印的方法,而不需要手動資源管理。

核心能力差距

RawPrint .NET 和IronPDF的根本區別在於它們的目的和功能:

任務RawPrint .NETIronPDF
從 HTML 建立 PDF不支援
從 URL 建立 PDF不支援
編輯/修改 PDF不支援
合併/分割 PDF不支援
列印現有 PDF是 (僅原始字節)是 (高階 API)
列印控制基本的完整選項
跨平台僅限 Windows

通过比较可以发现,RawPrint .NET 和IronPDF服务于完全不同的用例。RawPrint .NET處理低階印表機通訊,而IronPDFfor .NET 則提供完整的 PDF 文件生命週期管理。

HTML 至 PDF 轉換

在研究 HTML 到 PDF 的轉換方案時,RawPrint .NET 和IronPDF之間的對比就變得鮮明了。

RawPrint .NETHTML 處理

RawPrint .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
$vbLabelText   $csharpLabel

此程式碼展示了RawPrint .NET的限制:它會將原始 HTML 字串傳送至印表機,而非將其呈現為格式化的文件。 輸出將會是字面上的 HTML 標記文字,而非渲染的網頁。

IronPDFHTML 轉換

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

IronPDF 方法使用 RenderHtmlAsPdf 方法將 HTML 內容轉換為正確渲染的 PDF 文件。 Chromium 引擎會處理 CSS、JavaScript 和 HTML,以產生符合瀏覽器渲染的輸出。

URL 至 PDF 轉換

將實際網頁轉換為 PDF 進一步說明能力上的差異。

RawPrint .NETURL 處理。

RawPrint .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
$vbLabelText   $csharpLabel

此方法可下載 HTML 原始碼,並將其作為原始文字傳送至印表機。 翻譯的結果是列印的 HTML 標記,而不是包含樣式、圖片或排版的網頁。

IronPDFURL 轉換

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

RenderUrlAsPdf 方法會導航至 URL、執行 JavaScript、套用 CSS 定義、載入圖片,並擷取完整呈現的頁面為 PDF 文件。

文件格式比較

格式化能力揭示了兩種方法在架構上的差異。

RawPrint .NET格式化。

RawPrint .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
$vbLabelText   $csharpLabel

轉換順序 (\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
$vbLabelText   $csharpLabel

IronPdf 充分利用了現有的網路開發技能。 開發人員使用熟悉的 HTML 和 CSS 語法,而非特定於印表機的指令語言。 此方法可透過標準的網頁技術支援複雜的版面設計、字型、顏色和圖片。

API 對應參考。

評估RawPrint .NET移轉至IronPDF的團隊可參考此作業對應:

RawPrint .NETIronPDF
Printer.SendBytesToPrinter()<brpdf.Print()
Printer.OpenPrinter()不適用
Printer.ClosePrinter()不適用
Printer.StartDocPrinter()不適用
Printer.WritePrinter()不適用
Printer.EndDocPrinter()不適用
不適用ChromePdfRenderer`
不適用PdfDocument.Merge()
不適用pdf.ApplyWatermark()

映射結果顯示IronPDF完全省去了手動的印表機手柄管理。 在RawPrint .NET中需要顯式開啟/關閉/開始/結束呼叫的作業由IronPDF的高階 API 自動處理。

功能比較矩陣

特點RawPrint .NETIronPDF
PDF製作
HTML 至 PDF
URL 至 PDF
從零開始
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
$vbLabelText   $csharpLabel

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

IronPDF 提供了一種簡單的列印方法,可自動處理印表機通訊。 針對進階方案,IronPDF 支援列印選項,包括副本、DPI 和灰階設定。

當團隊考慮遷移RawPrint .NET時。

有幾個因素促使開發團隊評估RawPrint .NET的替代方案:

當應用程式需要建立 PDF 文件時,PDF 生成需求會成為阻礙因素。RawPrint .NET不能生成 PDF - 它只能將位元組傳輸至印表機。 需要將 HTML 轉換為 PDF 或建立文件的團隊必須在使用RawPrint .NET的同時使用其他函式庫。

跨平台部署要求超出了RawPrint .NET的能力。 本程式庫透過 winspool.Drv DLL 的匯入,完全仰賴視窗列印子系統。 Linux、macOS 和Docker部署需要不同的解決方案。

API 的複雜性造成維護上的負擔。 與高階 API 相比,使用明確的開啟/關閉/開始/結束順序進行手動印表機處理管理,會增加程式碼的複雜性和出錯的可能性。

有限的列印控制會影響生產需求。RawPrint .NET提供基本的位元組傳輸功能,但不提供複本、DPI、雙面列印或列印對話框等選項。

優勢與取捨

RawPrint .NET的優勢

  • 專用硬體的直接印表機存取 (標籤印表機、ZPL/EPL 裝置)
  • 將原始位元組傳輸的開銷降至最低
  • 適用於基本列印情境的簡單架構
  • 除視窗DLL 外,無其他外部依賴

RawPrint .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-to-PDF 轉換、文件處理或跨平台列印的應用程式,IronPDF 提供了RawPrint .NET完全無法提供的全面功能。 高階 API 可省去手動的印表機句柄管理,同時增加合併、分割、安全性和數位簽章等功能。

在評估將RawPrint .NET移植到IronPDF時,團隊應考慮其具體需求。 如果主要需求是 PDF 文件的建立和處理,列印則是次要功能,IronPDF 可解決完整的工作流程。 對於 2026 年以 .NET 10 和 C# 14 為目標、有跨平台部署需求的團隊而言,IronPDF 的架構提供了比視窗專用的RawPrint .NET方法更適當的基礎。


有關實施指導,請查閱IronPDF 文件列印教程,其中涵蓋了 .NET 應用程式的 PDF 生成和列印模式。