Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we explore how to use Iron Print to manage and execute your printing tasks efficiently. Starting with installation via the NuGet package manager, we dive into setting up the necessary environment within the Program.cs
file. The tutorial explains the use of the Iron Print library by including it in the namespace, which allows access to essential classes and methods. You learn to configure print settings like DPI for high-resolution prints and paper orientation for standard document formats. The core functionality is demonstrated using the printer async method, which requires the path of the PDF file and the pre-configured print settings to initiate the printing operation. The tutorial also clarifies why documents open in a PDF viewer instead of printing directly, explaining the role of the default printer settings in this behavior. By the end, viewers are encouraged to experiment with Iron Print using a trial subscription. This tutorial aims to simplify the printing process for C# developers, enabling them to produce high-quality printed documents seamlessly.
Below is an example code snippet illustrating how to use Iron Print:
using System;
using IronPrint;
class Program
{
static async Task Main(string[] args)
{
// Create a printer object from IronPrint
var printer = new IronPrint.Printer();
// Specify the path to the PDF document that needs to be printed
string pdfPath = "path/to/your/document.pdf";
// Configure print settings such as DPI and paper orientation
var printSettings = new IronPrint.PrintSettings
{
Dpi = 300, // High-resolution print
Orientation = IronPrint.PrintOrientation.Portrait // Standard document format
};
try
{
// Asynchronously print the document using the configured settings
await printer.PrintAsync(pdfPath, printSettings);
Console.WriteLine("Document sent to the printer successfully.");
}
catch (Exception ex)
{
// Handle any errors that may occur during the printing process
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
using System;
using IronPrint;
class Program
{
static async Task Main(string[] args)
{
// Create a printer object from IronPrint
var printer = new IronPrint.Printer();
// Specify the path to the PDF document that needs to be printed
string pdfPath = "path/to/your/document.pdf";
// Configure print settings such as DPI and paper orientation
var printSettings = new IronPrint.PrintSettings
{
Dpi = 300, // High-resolution print
Orientation = IronPrint.PrintOrientation.Portrait // Standard document format
};
try
{
// Asynchronously print the document using the configured settings
await printer.PrintAsync(pdfPath, printSettings);
Console.WriteLine("Document sent to the printer successfully.");
}
catch (Exception ex)
{
// Handle any errors that may occur during the printing process
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
Imports System
Imports IronPrint
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
' Create a printer object from IronPrint
Dim printer = New IronPrint.Printer()
' Specify the path to the PDF document that needs to be printed
Dim pdfPath As String = "path/to/your/document.pdf"
' Configure print settings such as DPI and paper orientation
Dim printSettings = New IronPrint.PrintSettings With {
.Dpi = 300,
.Orientation = IronPrint.PrintOrientation.Portrait
}
Try
' Asynchronously print the document using the configured settings
Await printer.PrintAsync(pdfPath, printSettings)
Console.WriteLine("Document sent to the printer successfully.")
Catch ex As Exception
' Handle any errors that may occur during the printing process
Console.WriteLine($"An error occurred: {ex.Message}")
End Try
End Function
End Class
Explanation:
System
for system functionalities and IronPrint
for printing capabilities.Printer
object is created, which provides methods to manage and execute printing tasks.PrintSettings
are configured with a chosen DPI for resolution and paper orientation.PrintAsync
method is called to initiate an asynchronous printing operation.try-catch
block is included to handle any potential errors during the printing process.Further Reading: Print Document Tutorial