Send to a Printer
The featured code example demonstrates IronPDF's document printing capability.
With the print
method, developers can make their applications print working PDF documents as part of its processing workflow. Invoking the print
method as demonstrated below will open the operating system's print dialog window, enabling the user to specify printing settings (printer, paper size, number of copies, etc.).
To print a PDF document immediately using the default printing settings, choose the printWithoutDialog
method instead of the print
method.
// Import necessary namespace
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Load an existing PDF document
var pdfDocument = PdfDocument.FromFile("example.pdf");
// Print the PDF with a print dialog
// This will open the operating system's print dialog window
pdfDocument.Print();
// Alternatively, to print the PDF immediately with default settings
// Uncomment the following line to use this method
// pdfDocument.PrintWithoutDialog();
}
}
// Import necessary namespace
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Load an existing PDF document
var pdfDocument = PdfDocument.FromFile("example.pdf");
// Print the PDF with a print dialog
// This will open the operating system's print dialog window
pdfDocument.Print();
// Alternatively, to print the PDF immediately with default settings
// Uncomment the following line to use this method
// pdfDocument.PrintWithoutDialog();
}
}
' Import necessary namespace
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Load an existing PDF document
Dim pdfDocument = PdfDocument.FromFile("example.pdf")
' Print the PDF with a print dialog
' This will open the operating system's print dialog window
pdfDocument.Print()
' Alternatively, to print the PDF immediately with default settings
' Uncomment the following line to use this method
' pdfDocument.PrintWithoutDialog();
End Sub
End Class
Explanation:
- The code begins by importing the necessary
IronPdf
namespace, allowing access to the PDF handling features provided by the IronPDF library. Program
class has aMain
method, which serves as the entry point of the application.- Inside the
Main
method, an existing PDF file namedexample.pdf
is loaded into aPdfDocument
object usingPdfDocument.FromFile()
. pdfDocument.Print();
calls thePrint
method, which opens the print dialog allowing users to make choices about how and where the document is printed.- The alternative
PrintWithoutDialog
method is commented out, providing developers an option to immediately send the document to the printer without any user interaction, using default settings.
Ensure you have IronPDF library installed and properly referenced in your project to run this code successfully.