Skip to footer content
MIGRATION GUIDES

How to Migrate from RawPrint to IronPDF in C#

Migrating from RawPrint to IronPDF transforms your document workflow from low-level printer byte transmission to a comprehensive PDF creation and printing solution. This guide provides a complete, step-by-step migration path that enables you to create, manipulate, and print PDFs with high-level APIs instead of manual printer handle management.

Why Migrate from RawPrint to IronPDF

Understanding RawPrint

RawPrint is a collection of implementations that enable sending raw data directly to a printer. It is essential for applications that require direct command transmission to printers, bypassing conventional printer drivers. This functionality is particularly useful in scenarios where specialized printers, such as label creators using ZPL (Zebra Programming Language) or EPL (Eltron Programming Language), are employed.

One strength of RawPrint is its simplicity in sending data streams directly to a printer. For developers targeting Windows-specific environments and requiring direct printer communication, RawPrint offers an efficient pathway bypassing intermediary layers like drivers or graphical interfaces.

However, RawPrint is NOT a PDF library—it just pushes data to printers. This fundamental limitation makes it the wrong choice for most document generation scenarios.

The Core Problem: No PDF Creation

RawPrint has notable limitations that make it unsuitable for modern document workflows:

  1. No PDF Creation: RawPrint focuses solely on data transmission, lacking functionality for PDF creation, rendering, or manipulation.

  2. Very Low-Level: By dealing directly with raw bytes, developers must have a deep understanding of the printer's command language, making it less suitable for straightforward document printing tasks.

  3. Platform-Specific: It depends on Windows print spoolers, limiting its cross-platform applicability.

  4. No Document Processing: Just byte transmission with no rendering capabilities.

  5. Limited Control: Minimal print job configuration options.

RawPrint vs IronPDF Comparison

Feature RawPrint IronPDF
Functionality Sends raw print data directly to the printer Comprehensive PDF creation and manipulation
Use Case Specialized printing like labels General document management and creation
Platform Dependency Windows-specific Cross-platform
Complexity Low-level, requires printer command knowledge High-level, user-friendly API
PDF Creation No Yes
Create PDF from HTML No Yes
Create PDF from URL No Yes
Edit/Modify PDFs No Yes
Merge/Split PDFs No Yes
Print Existing PDF Yes (raw bytes) Yes (high-level API)
Print Control Basic Full options
Ideal For Direct printer access needs PDF-related tasks in web and desktop apps
Flexibility Limited due to raw byte handling Extensive with multiple functionalities

In stark contrast to RawPrint, IronPDF offers a robust and versatile API for handling PDFs comprehensively. As an established name in the .NET environment, IronPDF enables developers to create, edit, and convert PDFs effortlessly across platforms.

For teams planning .NET 10 and C# 14 adoption through 2025 and 2026, IronPDF provides cross-platform compatibility that RawPrint cannot offer.


Before You Start

Prerequisites

  1. .NET Environment: .NET Framework 4.6.2+ or .NET Core 3.1+ / .NET 5/6/7/8/9+
  2. NuGet Access: Ability to install NuGet packages
  3. IronPDF License: Obtain your license key from ironpdf.com

NuGet Package Changes

# Remove RawPrint
dotnet remove package RawPrint

# Install IronPDF
dotnet add package IronPdf
# Remove RawPrint
dotnet remove package RawPrint

# Install IronPDF
dotnet add package IronPdf
SHELL

License Configuration

// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

Find RawPrint Usage

# Identify all RawPrint usage
grep -r "using RawPrint" --include="*.cs" .
grep -r "Printer\|SendBytesToPrinter" --include="*.cs" .
# Identify all RawPrint usage
grep -r "using RawPrint" --include="*.cs" .
grep -r "Printer\|SendBytesToPrinter" --include="*.cs" .
SHELL

Complete API Reference

Namespace Changes

// Before: RawPrint (Windows interop)
using System.Runtime.InteropServices;
using System.Drawing.Printing;

// After: IronPDF
using IronPdf;
// Before: RawPrint (Windows interop)
using System.Runtime.InteropServices;
using System.Drawing.Printing;

// After: IronPDF
using IronPdf;
' Before: RawPrint (Windows interop)
Imports System.Runtime.InteropServices
Imports System.Drawing.Printing

' After: IronPDF
Imports IronPdf
$vbLabelText   $csharpLabel

Core API Mappings

RawPrint IronPDF Notes
Printer.SendBytesToPrinter() pdf.Print() High-level printing
Printer.OpenPrinter() N/A Not needed
Printer.ClosePrinter() N/A Automatic
Printer.StartDocPrinter() N/A Automatic
Printer.WritePrinter() N/A Automatic
Printer.EndDocPrinter() N/A Automatic
N/A ChromePdfRenderer Create PDFs
N/A PdfDocument.Merge() Merge PDFs
N/A pdf.ApplyWatermark() Add watermarks

Code Migration Examples

Example 1: HTML to PDF Conversion

Before (RawPrint):

// 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

After (IronPDF):

// 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

This example demonstrates the fundamental architectural difference. RawPrint requires 60+ lines of code with multiple DLL imports from winspool.Drv, manual printer handle management (OpenPrinter, StartDocPrinter, WritePrinter, EndDocPrinter, ClosePrinter), and memory marshaling—and it still cannot create a PDF. It only sends raw data to the printer with no rendering capability.

IronPDF accomplishes the task in 5 lines: create a ChromePdfRenderer, call RenderHtmlAsPdf(), and SaveAs(). See the HTML to PDF documentation for comprehensive examples.

Example 2: URL to PDF Conversion

Before (RawPrint):

// NuGet: Install-Package System.Drawing.Common
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;

class RawPrinterHelper
{
    // ... (same DLL imports as above) ...

    public static bool SendStringToPrinter(string szPrinterName, string szString)
    {
        IntPtr pBytes = Marshal.StringToCoTaskMemAnsi(szString);
        IntPtr hPrinter;
        if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
        {
            DOCINFOA di = new DOCINFOA();
            di.pDocName = "Web Page";
            di.pDataType = "RAW";
            if (StartDocPrinter(hPrinter, 1, di))
            {
                if (StartPagePrinter(hPrinter))
                {
                    Int32 dwWritten;
                    WritePrinter(hPrinter, pBytes, szString.Length, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
            Marshal.FreeCoTaskMem(pBytes);
            return true;
        }
        return false;
    }
}

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 RawPrinterHelper
{
    // ... (same DLL imports as above) ...

    public static bool SendStringToPrinter(string szPrinterName, string szString)
    {
        IntPtr pBytes = Marshal.StringToCoTaskMemAnsi(szString);
        IntPtr hPrinter;
        if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
        {
            DOCINFOA di = new DOCINFOA();
            di.pDocName = "Web Page";
            di.pDataType = "RAW";
            if (StartDocPrinter(hPrinter, 1, di))
            {
                if (StartPagePrinter(hPrinter))
                {
                    Int32 dwWritten;
                    WritePrinter(hPrinter, pBytes, szString.Length, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
            Marshal.FreeCoTaskMem(pBytes);
            return true;
        }
        return false;
    }
}

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
Imports System
Imports System.Net
Imports System.Runtime.InteropServices
Imports System.Text

Class RawPrinterHelper
    ' ... (same DLL imports as above) ...

    Public Shared Function SendStringToPrinter(ByVal szPrinterName As String, ByVal szString As String) As Boolean
        Dim pBytes As IntPtr = Marshal.StringToCoTaskMemAnsi(szString)
        Dim hPrinter As IntPtr
        If OpenPrinter(szPrinterName, hPrinter, IntPtr.Zero) Then
            Dim di As New DOCINFOA()
            di.pDocName = "Web Page"
            di.pDataType = "RAW"
            If StartDocPrinter(hPrinter, 1, di) Then
                If StartPagePrinter(hPrinter) Then
                    Dim dwWritten As Integer
                    WritePrinter(hPrinter, pBytes, szString.Length, 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()
        ' 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 Class
$vbLabelText   $csharpLabel

After (IronPDF):

// 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

RawPrint cannot render web pages—it only sends raw text/data. The RawPrint approach downloads HTML source and sends it directly to the printer, resulting in raw HTML code being printed, not rendered content. IronPDF's RenderUrlAsPdf() captures the fully rendered webpage with CSS, JavaScript, and images. Learn more in our tutorials.

Example 3: Document Formatting

Before (RawPrint):

// NuGet: Install-Package System.Drawing.Common
using System;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Text;

class RawPrinterHelper
{
    // ... (same DLL imports) ...

    public static bool SendBytesToPrinter(string szPrinterName, byte[] pBytes)
    {
        IntPtr pUnmanagedBytes = Marshal.AllocCoTaskMem(pBytes.Length);
        Marshal.Copy(pBytes, 0, pUnmanagedBytes, pBytes.Length);
        IntPtr hPrinter;
        if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
        {
            DOCINFOA di = new DOCINFOA();
            di.pDocName = "Raw Document";
            di.pDataType = "RAW";
            if (StartDocPrinter(hPrinter, 1, di))
            {
                if (StartPagePrinter(hPrinter))
                {
                    Int32 dwWritten;
                    WritePrinter(hPrinter, pUnmanagedBytes, pBytes.Length, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
            Marshal.FreeCoTaskMem(pUnmanagedBytes);
            return true;
        }
        return false;
    }
}

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 RawPrinterHelper
{
    // ... (same DLL imports) ...

    public static bool SendBytesToPrinter(string szPrinterName, byte[] pBytes)
    {
        IntPtr pUnmanagedBytes = Marshal.AllocCoTaskMem(pBytes.Length);
        Marshal.Copy(pBytes, 0, pUnmanagedBytes, pBytes.Length);
        IntPtr hPrinter;
        if (OpenPrinter(szPrinterName, out hPrinter, IntPtr.Zero))
        {
            DOCINFOA di = new DOCINFOA();
            di.pDocName = "Raw Document";
            di.pDataType = "RAW";
            if (StartDocPrinter(hPrinter, 1, di))
            {
                if (StartPagePrinter(hPrinter))
                {
                    Int32 dwWritten;
                    WritePrinter(hPrinter, pUnmanagedBytes, pBytes.Length, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
            Marshal.FreeCoTaskMem(pUnmanagedBytes);
            return true;
        }
        return false;
    }
}

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
Imports System
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Imports System.Text

Class RawPrinterHelper
    ' ... (same DLL imports) ...

    Public Shared Function SendBytesToPrinter(szPrinterName As String, pBytes As Byte()) As Boolean
        Dim pUnmanagedBytes As IntPtr = Marshal.AllocCoTaskMem(pBytes.Length)
        Marshal.Copy(pBytes, 0, pUnmanagedBytes, pBytes.Length)
        Dim hPrinter As IntPtr
        If OpenPrinter(szPrinterName, hPrinter, IntPtr.Zero) Then
            Dim di As New DOCINFOA()
            di.pDocName = "Raw Document"
            di.pDataType = "RAW"
            If StartDocPrinter(hPrinter, 1, di) Then
                If StartPagePrinter(hPrinter) Then
                    Dim dwWritten As Int32
                    WritePrinter(hPrinter, pUnmanagedBytes, pBytes.Length, dwWritten)
                    EndPagePrinter(hPrinter)
                End If
                EndDocPrinter(hPrinter)
            End If
            ClosePrinter(hPrinter)
            Marshal.FreeCoTaskMem(pUnmanagedBytes)
            Return True
        End If
        Return False
    End Function
End Class

Class Program
    Shared Sub Main()
        ' RawPrint requires manual PCL/PostScript commands for formatting
        Dim pclCommands As String = Chr(&H1B) & "&l0O" & Chr(&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 Class
$vbLabelText   $csharpLabel

After (IronPDF):

// 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

RawPrint requires manual PCL/PostScript commands ("\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T") for even basic formatting. Developers must have deep understanding of the printer's command language. IronPDF uses standard HTML and CSS for formatting—complex layouts, fonts, colors, and images are fully supported without printer-specific knowledge.


Feature Comparison Summary

Feature RawPrint IronPDF
:PDF Creation: HTML to PDF No Yes
URL to PDF No Yes
Create from scratch No Yes
:PDF Manipulation: Merge PDFs No Yes
Split PDFs No Yes
Add Watermarks No Yes
Edit Existing No Yes
:Printing: Print PDF Yes (raw) Yes (high-level)
Print Dialog No Yes
Multiple Copies Limited Yes
DPI Control No Yes
Duplex No Yes
:Platform: Windows Yes Yes
Linux No Yes
macOS No Yes
Docker No Yes
:Other: Security No Yes
Digital Signatures No Yes
PDF/A No Yes

New Capabilities After Migration

After migrating to IronPDF, you gain capabilities that RawPrint cannot provide:

PDF Merging

var pdfs = pdfFiles.Select(f => PdfDocument.FromFile(f)).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("complete.pdf");
var pdfs = pdfFiles.Select(f => PdfDocument.FromFile(f)).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("complete.pdf");
Dim pdfs = pdfFiles.Select(Function(f) PdfDocument.FromFile(f)).ToList()
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("complete.pdf")
$vbLabelText   $csharpLabel

Print with Settings

var pdf = PdfDocument.FromFile("report.pdf");

pdf.Print(new PrintOptions
{
    PrinterName = "HP LaserJet",
    NumberOfCopies = 2,
    DPI = 300,
    GrayScale = false
});
var pdf = PdfDocument.FromFile("report.pdf");

pdf.Print(new PrintOptions
{
    PrinterName = "HP LaserJet",
    NumberOfCopies = 2,
    DPI = 300,
    GrayScale = false
});
Dim pdf = PdfDocument.FromFile("report.pdf")

pdf.Print(New PrintOptions With {
    .PrinterName = "HP LaserJet",
    .NumberOfCopies = 2,
    .DPI = 300,
    .GrayScale = False
})
$vbLabelText   $csharpLabel

Create and Print in One Workflow

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
    <h1>Invoice #12345</h1>
    <p>Customer: John Doe</p>
    <p>Amount: $150.00</p>
");

// Print directly
pdf.Print("HP LaserJet");

// Or save first
pdf.SaveAs("invoice.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
    <h1>Invoice #12345</h1>
    <p>Customer: John Doe</p>
    <p>Amount: $150.00</p>
");

// Print directly
pdf.Print("HP LaserJet");

// Or save first
pdf.SaveAs("invoice.pdf");
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
    <h1>Invoice #12345</h1>
    <p>Customer: John Doe</p>
    <p>Amount: $150.00</p>
")

' Print directly
pdf.Print("HP LaserJet")

' Or save first
pdf.SaveAs("invoice.pdf")
$vbLabelText   $csharpLabel

Migration Checklist

Pre-Migration

  • Identify all RawPrint usage (SendBytesToPrinter, OpenPrinter, etc.)
  • Document printer names used in your application
  • Note any external PDF creation code that can be consolidated
  • Obtain IronPDF license key from ironpdf.com

Code Updates

  • Remove RawPrint package: dotnet remove package RawPrint
  • Install IronPdf package: dotnet add package IronPdf
  • Replace raw printing with pdf.Print()
  • Remove manual handle management (OpenPrinter, ClosePrinter, etc.)
  • Consolidate PDF creation and printing into single workflow
  • Add license initialization at application startup

Testing

  • Test printing to target printers
  • Verify print quality
  • Test multiple copies
  • Test silent printing
  • Cross-platform verification if needed

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me