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
    %s requires a valid license key for further deployment. Get Trial Below.
    ironsuite
    Blue key in circleGet Started for Free
    30 days full access • 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.
    Grey check in circleTrial key delivered
    Your key has been issued and sent to your email.
    Calendar in circleBook Free Live Demo
    No cards • no pitches • no commitments Pick a time for a quick, personalized demo
    Get the most out of your 30-day trial with:

    Live product and key features walk-through

    Project-specific recommendations

    All your questions answered

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation

    Want to deploy Iron Suite
    to a live project for FREE?

    What’s included?

    • Test in production without watermarks
    • 30 days fully functional product
    • 24/5 technical support during trial
    ironpdf Logo
    ironword Logo
    ironxl Logo
    ironppt Logo
    ironocr Logo
    ironbarcode Logo
    ironqr Logo
    ironprint Logo
    ironzip Logo
    ironwebscraper Logo
    Iron Software sales team
    Online 24/5
    Have Enterprise licensing requirements?
    Request Iron Suite Enterprise trial
    Key in blue circle

    Get your free 30-day Trial Key instantly

    Your trial license will be sent to your email address

    No limitations. 100% unlocked. No credit card.

    bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
    Or
    Key in blue circle

    Complete Your Trial Key Signup

    Tell us a little more about yourself.

    Key in blue circleNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
    Key in blue circle

    Your license key has been delivered to your inbox

    Can't find it? Check your spam folder.

    What’s next?
    Install with NuGet
    Add IronPrint to your project
    Quickstart Guide
    Helpful resources to get started

    Need help getting started?

    Book a Free Live Demo

    See IronPrint in action and get your licensing questions answered, or

    Key in blue circle

    Your demo request is in.

    You'll receive an invite via email shortly.

    What’s next?
    Explore Documentation
    Review Licensing Options
    badge_greencheck_in_yellowcircle
    Thank you
    Your trial key should be in the email.
    If it is not, please contact support@ironsoftware.com
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronPrint
    Your trial key should be in the email.
    If it is not, please contact support@ironsoftware.com