Search Results for

    Show / Hide Table of Contents

    Class Printer

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

    • PDF
    • PNG
    • JPG
    • BMP
    • TIFF
    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

    Printer sends a document to a physical printer from C#, and it does so on Windows, macOS, Linux, Android, and iOS through one API. Hand it a file path or a byte[] of file data and it queues the job on the default printer or on one named through PrintSettings. Jobs print silently by default, so a server or background service can print with no user present.

    The members fall into three groups. Printing methods (Print and PrintAsync) send a job straight to the device. The interactive methods (ShowPrintDialog and ShowPrintDialogAsync) open the operating system print dialog so the user picks the printer and options. The discovery methods (GetPrinterNames and GetPrinterTrays) list the printers and trays available on the machine. Because the class is static, there is nothing to construct: call the methods directly after rendering or loading the file you want on paper. Every printing and dialog call takes an optional PrintSettings, and each has an asynchronous form that returns a Task to keep the operation off the calling thread.

    A typical job builds a PrintSettings, sets the values that matter, and passes it to Print. When the target device is not known ahead of time, call GetPrinterNames first and assign the chosen name to PrintSettings.PrinterName, or call ShowPrintDialog and let the user choose. Where blocking the thread is a concern, prefer PrintAsync or ShowPrintDialogAsync and await the returned Task. The print settings guide covers the options each call accepts.

    using IronPrint;
    
    PrintSettings settings = new PrintSettings { NumberOfCopies = 2 };
    Printer.Print("invoice.pdf", settings);

    The silent printing guide walks through unattended jobs, the print with dialog guide covers interactive printing, and the retrieve printer names guide shows how to enumerate devices first.

    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