IronPrint: Cross-Platform Printing Solution
IronPrint is a versatile tool designed to facilitate document printing across multiple operating systems, including Windows, macOS, Linux, Android, and iOS. It extends support to various .NET projects, offering seamless integration with Avalonia, MAUI, Xamarin (Xamarin.iOS, Xamarin.Android & Xamarin.Forms), and WPF.
Using the Print
Method
To print documents to a default printer, utilize the Print
method. This method can be configured with specific printer settings using the PrintSettings object.
Here is an example of how to use IronPrint for printing documents:
// Import necessary namespace
using IronPrint;
// Example class demonstrating how to use IronPrint
public class DocumentPrinter
{
public void PrintDocument(string documentPath)
{
// Initialize a new instance of the PrinterSettings class.
PrinterSettings settings = new PrinterSettings();
// Configure desired printer settings.
settings.Duplex = true; // Enable duplex printing
settings.Color = true; // Enable color printing
settings.PaperSize = "A4"; // Set paper size to A4
// Use the Print method to send the document to the default printer.
// The documentPath specifies the path to the document to be printed.
Printer.Print(documentPath, settings);
// Output indicating the process.
Console.WriteLine("Document has been sent to the printer.");
}
}
// Usage example
class Program
{
static void Main()
{
// Create an instance of the DocumentPrinter class
DocumentPrinter printer = new DocumentPrinter();
// Specify the document to be printed
string documentPath = "C:\\Documents\\example.docx";
// Call the PrintDocument method
printer.PrintDocument(documentPath);
}
}
// Import necessary namespace
using IronPrint;
// Example class demonstrating how to use IronPrint
public class DocumentPrinter
{
public void PrintDocument(string documentPath)
{
// Initialize a new instance of the PrinterSettings class.
PrinterSettings settings = new PrinterSettings();
// Configure desired printer settings.
settings.Duplex = true; // Enable duplex printing
settings.Color = true; // Enable color printing
settings.PaperSize = "A4"; // Set paper size to A4
// Use the Print method to send the document to the default printer.
// The documentPath specifies the path to the document to be printed.
Printer.Print(documentPath, settings);
// Output indicating the process.
Console.WriteLine("Document has been sent to the printer.");
}
}
// Usage example
class Program
{
static void Main()
{
// Create an instance of the DocumentPrinter class
DocumentPrinter printer = new DocumentPrinter();
// Specify the document to be printed
string documentPath = "C:\\Documents\\example.docx";
// Call the PrintDocument method
printer.PrintDocument(documentPath);
}
}
' Import necessary namespace
Imports IronPrint
' Example class demonstrating how to use IronPrint
Public Class DocumentPrinter
Public Sub PrintDocument(ByVal documentPath As String)
' Initialize a new instance of the PrinterSettings class.
Dim settings As New PrinterSettings()
' Configure desired printer settings.
settings.Duplex = True ' Enable duplex printing
settings.Color = True ' Enable color printing
settings.PaperSize = "A4" ' Set paper size to A4
' Use the Print method to send the document to the default printer.
' The documentPath specifies the path to the document to be printed.
Printer.Print(documentPath, settings)
' Output indicating the process.
Console.WriteLine("Document has been sent to the printer.")
End Sub
End Class
' Usage example
Friend Class Program
Shared Sub Main()
' Create an instance of the DocumentPrinter class
Dim printer As New DocumentPrinter()
' Specify the document to be printed
Dim documentPath As String = "C:\Documents\example.docx"
' Call the PrintDocument method
printer.PrintDocument(documentPath)
End Sub
End Class
Code Explanation:
- Namespaces: The
using IronPrint;
directive imports the IronPrint library, necessary for accessing the print functionalities. - PrinterSettings Object: An instance of
PrinterSettings
is created to define print configurations like duplex, color, and paper size. - Print Method: Invoked with
Printer.Print(documentPath, settings);
to send a document to the printer using specified settings. - Console Output: Provides confirmation after sending the print job, helping users track the process.
Ensure the necessary libraries are correctly referenced in your project to utilize IronPrint effectively.