Class Printer
The Printer
class allows you to easily print various file types including:
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
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 |
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 |
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. |