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
Table of Contents
- Print Document
- Apply Print Settings
- Get Printer Information
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
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
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
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
Frequently Asked Questions
What is IronPrint?
IronPrint is a powerful printing library designed for .NET C# developers to integrate printing capabilities into their applications across various platforms like Windows, macOS, iOS, and Android.
How can I print documents silently using IronPrint?
You can print documents silently by using the PrintSilently() method of a PrintJob instance, which executes the print job without displaying the print dialog.
Can I customize print settings programmatically with IronPrint?
Yes, IronPrint allows you to adjust print settings programmatically. You can customize settings such as color mode, duplex mode, and the number of copies through code before executing the print job.
What platforms does IronPrint support?
IronPrint supports multiple platforms, including Windows, macOS, iOS, and Android, ensuring consistent and reliable printing capabilities across these operating systems.
How do I initiate a print job with a dialog using IronPrint?
To start a print job with a dialog, use the PrintWithDialog() method on a PrintJob instance, which allows users to interact with the print settings dialog before printing.
Is it possible to retrieve printer information using IronPrint?
Yes, you can retrieve a list of available printers on the system using the PrinterSettings.GetAvailablePrinters() method, which helps in dynamic printer selection.
Can IronPrint handle different document formats?
IronPrint can handle various document formats, including PDF, PNG, HTML, TIFF, GIF, JPEG, IMAGE, and BITMAP, allowing versatile document printing.