Search Results for

    Show / Hide Table of Contents

    Class Printer

    The Printer class allows you to easily print various file types including:

    You can achieve this by passing either a file path or file data as a byte[].

    Call `Printer.Print()` for silent printing

    Call `Printer.ShowPrintDialog()` for display the print dialog.

    We also provide an `Async` functions to prevent the print operation from blocking your thread.
    Inheritance
    System.Object
    Printer
    Namespace: IronPrint
    Assembly: IronPrint.dll
    Syntax
    public static class Printer : Object
    Remarks

    Note: The print result and print dialog may vary based on your platform.

    ------------------------------------------------

    Supports:

    Project Types: MAUI, WPF, Windows Forms

    .NET version: .NET Framework 4.6.2 and above, .NET3.1 and above (including .NET5 .NET6 .NET7 and .NET8)

    OS: Windows, Android, iOS, macOS

    When working with .NET Core projects (including .NET 5 and above), specifying the target OS in your .csproj file using the TargetFrameworks property is indeed necessary.

    This ensures that IronPrint can utilize OS-specific UI components for printing operations on your target platform.

    For example, if you’re targeting Windows, Android, iOS, or macOS, you should adjust your TargetFrameworks accordingly. Change net6.0 to net6.0-windows, net6.0-android, net6.0-ios, net6.0-macos, or net6.0-maccatalyst, depending on your desired platform.

    you can specify multiple TargetFrameworks for your cross-platform project e.g. `net6.0-ios;net6.0-macos;net6.0-maccatalyst;net6.0-android;`

    Note: For Android projects `Printer.Initialize(Android.Content.Context mainActivity)` needs to be called before printing.

    Methods

    GetPrinterNames()

    Retrieves a list of printer names available on the system.

    Declaration
    public static List<string> GetPrinterNames()
    Returns
    Type Description
    System.Collections.Generic.List<System.String>

    A list of strings, each representing a printer name.

    GetPrinterNamesAsync()

    Asynchronously retrieves a list of printer names available on the system.

    Declaration
    public static Task<List<string>> GetPrinterNamesAsync()
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Collections.Generic.List<System.String>>

    The task result contains a list of strings, each representing a printer name.

    GetPrinterTrays(String)

    Retrieves a list of printer tray available on the specified printer, or for a default printer if no specific printer is provided.

    Declaration
    public static List<string> GetPrinterTrays(string printerName = null)
    Parameters
    Type Name Description
    System.String printerName

    The name of the printer for which to retrieve tray information. Default null for a default printer

    Returns
    Type Description
    System.Collections.Generic.List<System.String>

    A list of strings, each representing a tray name.

    GetPrinterTraysAsync(String)

    Asynchronously retrieves a list of printer tray available on the specified printer, or for a default printer if no specific printer is provided.

    Declaration
    public static Task<List<string>> GetPrinterTraysAsync(string printerName = null)
    Parameters
    Type Name Description
    System.String printerName

    The name of the printer for which to retrieve tray information. Default null for a default printer

    Returns
    Type Description
    System.Threading.Tasks.Task<System.Collections.Generic.List<System.String>>

    The task result contains a list of strings, each representing a tray name.

    Print(Byte[], PrintSettings)

    Silently print (without a dialog) from a PDF or an image file data.

    Declaration
    public static void Print(byte[] fileData, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.Byte[] fileData

    A PDF or an image file data in byte[]

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Remarks

    Note: If this operation block your thread, Please use PrintAsync(Byte[], PrintSettings) instead

    Note: In mobile, Silently print is not possible. This operation will show print dialog anyways

    Print(String, PrintSettings)

    Silently print (without a dialog) from a PDF or an image file path.

    Declaration
    public static void Print(string path, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.String path

    The path of a PDF or an image.

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Remarks

    Note: If this operation block your thread, Please use PrintAsync(String, PrintSettings) instead

    Note: In mobile, Silently print is not possible. This operation will show print dialog anyways

    PrintAsync(Byte[], PrintSettings)

    Silently print asynchronously (without a dialog) from a PDF or an image file data.

    Declaration
    public static Task PrintAsync(byte[] fileData, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.Byte[] fileData

    A PDF or an image file data in byte[]

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Returns
    Type Description
    System.Threading.Tasks.Task

    An awaitable task that starts printing.

    Remarks

    Note: In mobile, Silently print is not possible. This operation will show print dialog anyways

    PrintAsync(String, PrintSettings)

    Silently print asynchronously (without a dialog) from a PDF or an image file path.

    Declaration
    public static Task PrintAsync(string path, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.String path

    The path of a PDF or an image file.

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Returns
    Type Description
    System.Threading.Tasks.Task

    An awaitable task that starts printing.

    Remarks

    Note: In mobile, Silently print is not possible. This operation will show print dialog anyways

    ShowPrintDialog(Byte[], PrintSettings)

    Shows a print dialog asynchronously for a PDF or an image file data in byte[].

    The visual and functional aspects of the print dialog may vary based on your platform.

    Declaration
    public static void ShowPrintDialog(byte[] fileData, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.Byte[] fileData

    A PDF or an image file data in byte[]

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Remarks

    Note: If this operation block your thread, Please use ShowPrintDialogAsync(Byte[], PrintSettings) instead

    ShowPrintDialog(String, PrintSettings)

    Shows a print dialog for a PDF or an image path.

    The visual and functional aspects of the print dialog may vary based on your platform.

    Declaration
    public static void ShowPrintDialog(string path, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.String path

    The path of a document.

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Remarks

    Note: If this operation block your thread, Please use ShowPrintDialogAsync(String, PrintSettings) instead

    ShowPrintDialogAsync(Byte[], PrintSettings)

    Shows a print dialog asynchronously for a PDF or an image file data in byte[].

    The visual and functional aspects of the print dialog may vary based on your platform.

    Declaration
    public static Task ShowPrintDialogAsync(byte[] fileData, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.Byte[] fileData

    A PDF or an image file data in byte[]

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Returns
    Type Description
    System.Threading.Tasks.Task

    An awaitable task that shows a printing dialog.

    ShowPrintDialogAsync(String, PrintSettings)

    Shows a print dialog asynchronously for a PDF or an image path.

    The visual and functional aspects of the print dialog may vary based on your platform.

    Declaration
    public static Task ShowPrintDialogAsync(string path, PrintSettings settings = null)
    Parameters
    Type Name Description
    System.String path

    The path of a document.

    PrintSettings settings

    (Optional) The PrintSettings to use for printing.

    Returns
    Type Description
    System.Threading.Tasks.Task

    An awaitable task that shows a printing dialog.

    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet
    IronPrint_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronPrint