Print Document Tutorial

IronPrint is a powerful printing library designed to assist .NET C# developers in integrating printing capabilities into their applications. With a broad compatibility spectrum spanning across Windows, macOS, iOS, and Android platforms, IronPrint works consistently and reliably across diverse operating systems. Whether you are creating applications for desktop environments, Apple's macOS ecosystem, or mobile platforms like iOS and Android, IronPrint simplifies the implementation of printing features, providing a versatile and user-friendly solution for all your printing needs in the .NET C# environment.

Get started with IronPrint

Start using IronPrint in your project today with a free trial.

First Step:
green arrow pointer


Table of Contents

Print Document

Print Silently

Print documents seamlessly without displaying the print dialog. The print settings can then be done directly within the code.

// Programmatically print a document without showing the print dialog.
// Define your print job and settings here as needed.

using System;
using IronPrint;

public class SilentPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a silent print job
        var printJob = new PrintJob(document);

        // Apply specific settings as necessary
        // For example: set printer name, copies, etc.

        // Execute the print job
        printJob.PrintSilently();
    }
}
// Programmatically print a document without showing the print dialog.
// Define your print job and settings here as needed.

using System;
using IronPrint;

public class SilentPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a silent print job
        var printJob = new PrintJob(document);

        // Apply specific settings as necessary
        // For example: set printer name, copies, etc.

        // Execute the print job
        printJob.PrintSilently();
    }
}
' Programmatically print a document without showing the print dialog.
' Define your print job and settings here as needed.

Imports System
Imports IronPrint

Public Class SilentPrint
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Initialize a silent print job
		Dim printJob As New PrintJob(document)

		' Apply specific settings as necessary
		' For example: set printer name, copies, etc.

		' Execute the print job
		printJob.PrintSilently()
	End Sub
End Class
$vbLabelText   $csharpLabel

Print With Dialog

Initiate the printing process with the print setting dialog displayed. This allows users to customize print options interactively.

// Start a print job with user interaction through the print dialog.

using System;
using IronPrint;

public class DialogPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a print job with dialog
        var printJob = new PrintJob(document);

        // Execute the print job with display of print options dialog
        printJob.PrintWithDialog();
    }
}
// Start a print job with user interaction through the print dialog.

using System;
using IronPrint;

public class DialogPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a print job with dialog
        var printJob = new PrintJob(document);

        // Execute the print job with display of print options dialog
        printJob.PrintWithDialog();
    }
}
' Start a print job with user interaction through the print dialog.

Imports System
Imports IronPrint

Public Class DialogPrint
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Initialize a print job with dialog
		Dim printJob As New PrintJob(document)

		' Execute the print job with display of print options dialog
		printJob.PrintWithDialog()
	End Sub
End Class
$vbLabelText   $csharpLabel

Apply Print Settings

Programmatically adjust print settings to meet specific requirements. This section provides the capability to fine-tune printing configurations through code.

// Example code to apply custom print settings programmatically.

using System;
using IronPrint;

public class PrintSettingsExample
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Create a print job
        var printJob = new PrintJob(document);

        // Set custom print settings like duplex, color mode, etc.
        var settings = new PrintSettings
        {
            ColorMode = ColorMode.Color,
            DuplexMode = DuplexMode.OneSided,
            Copies = 2
        };

        // Apply settings to print job
        printJob.ApplySettings(settings);

        // Print the document
        printJob.PrintSilently();
    }
}
// Example code to apply custom print settings programmatically.

using System;
using IronPrint;

public class PrintSettingsExample
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Create a print job
        var printJob = new PrintJob(document);

        // Set custom print settings like duplex, color mode, etc.
        var settings = new PrintSettings
        {
            ColorMode = ColorMode.Color,
            DuplexMode = DuplexMode.OneSided,
            Copies = 2
        };

        // Apply settings to print job
        printJob.ApplySettings(settings);

        // Print the document
        printJob.PrintSilently();
    }
}
' Example code to apply custom print settings programmatically.

Imports System
Imports IronPrint

Public Class PrintSettingsExample
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Create a print job
		Dim printJob As New PrintJob(document)

		' Set custom print settings like duplex, color mode, etc.
		Dim settings = New PrintSettings With {
			.ColorMode = ColorMode.Color,
			.DuplexMode = DuplexMode.OneSided,
			.Copies = 2
		}

		' Apply settings to print job
		printJob.ApplySettings(settings)

		' Print the document
		printJob.PrintSilently()
	End Sub
End Class
$vbLabelText   $csharpLabel

Get Printer Information

Get Printer Names

Access a list of all available printers. Retrieve the names of printers installed on the system for informative purposes or dynamic printer selection in your application.

// Retrieve and display a list of printer names available on the system.

using System;
using IronPrint;

public class PrinterInfo
{
    public static void Main()
    {
        // Get an enumerable list of printer names
        var printerNames = PrinterSettings.GetAvailablePrinters();

        // Print each printer name to the console
        Console.WriteLine("Available Printers:");
        foreach (var name in printerNames)
        {
            Console.WriteLine(name);
        }
    }
}
// Retrieve and display a list of printer names available on the system.

using System;
using IronPrint;

public class PrinterInfo
{
    public static void Main()
    {
        // Get an enumerable list of printer names
        var printerNames = PrinterSettings.GetAvailablePrinters();

        // Print each printer name to the console
        Console.WriteLine("Available Printers:");
        foreach (var name in printerNames)
        {
            Console.WriteLine(name);
        }
    }
}
' Retrieve and display a list of printer names available on the system.

Imports System
Imports IronPrint

Public Class PrinterInfo
	Public Shared Sub Main()
		' Get an enumerable list of printer names
		Dim printerNames = PrinterSettings.GetAvailablePrinters()

		' Print each printer name to the console
		Console.WriteLine("Available Printers:")
		For Each name In printerNames
			Console.WriteLine(name)
		Next name
	End Sub
End Class
$vbLabelText   $csharpLabel

Frequently Asked Questions

How can I print documents silently in .NET C#?

You can use the PrintSilently() method of a PrintJob instance to execute print jobs without user interaction. This allows the document to be printed programmatically without displaying the print dialog.

What is the process to print a document with a print dialog in .NET C#?

You can initiate a print job with user interaction by using the PrintWithDialog() method on a PrintJob instance. This displays the print settings dialog, allowing users to customize options before printing.

Is it possible to apply custom print settings programmatically in .NET C#?

Yes, you can programmatically apply custom print settings by creating a PrintSettings object and configuring properties such as color mode, duplex mode, and the number of copies. These settings can then be applied to a PrintJob instance.

How can I retrieve available printer names in a .NET C# application?

You can retrieve available printer names using the PrinterSettings.GetAvailablePrinters() method. This provides an enumerable list of printer names installed on the system for selection or informative purposes.

Can I print different document formats using a .NET C# library?

Yes, the library supports printing various document formats, including PDF, PNG, HTML, TIFF, GIF, JPEG, IMAGE, and BITMAP, allowing for versatile document printing options.

What platforms are supported for printing documents using the .NET C# library?

The library supports multiple platforms, such as Windows, macOS, iOS, and Android, ensuring consistent and reliable printing capabilities across these operating systems.

How does silent printing differ from dialog-based printing in .NET C#?

Silent printing allows documents to be printed programmatically without user interaction, using the PrintSilently() method. Dialog-based printing involves displaying a print dialog for user customization, achieved through the PrintWithDialog() method.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.