Paper Printing PDFs
using System;
using System.Drawing.Printing;
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Create a PDF document from a file
var pdf = PdfDocument.FromFile("example.pdf");
// Print the PDF using the default printer with dialogue
pdf.Print();
// To print without showing the Windows print dialog, use the overload:
pdf.Print(printerSettings: new PrinterSettings(), showPrintDialog: false);
// Alternatively, you can get a PrintDocument object for more options
PrintDocument printDoc = pdf.GetPrintDocument();
// You can customize the printing settings using the PrintDocument object
// before executing the print
printDoc.PrintPage += new PrintPageEventHandler(PrintPageHandler);
// Execute the print
printDoc.Print();
}
// Define a method to handle the print page event
static void PrintPageHandler(object sender, PrintPageEventArgs e)
{
// Print page settings and logic can be handled here
e.HasMorePages = false; // Set to true if there are more pages to print
}
}
using System;
using System.Drawing.Printing;
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Create a PDF document from a file
var pdf = PdfDocument.FromFile("example.pdf");
// Print the PDF using the default printer with dialogue
pdf.Print();
// To print without showing the Windows print dialog, use the overload:
pdf.Print(printerSettings: new PrinterSettings(), showPrintDialog: false);
// Alternatively, you can get a PrintDocument object for more options
PrintDocument printDoc = pdf.GetPrintDocument();
// You can customize the printing settings using the PrintDocument object
// before executing the print
printDoc.PrintPage += new PrintPageEventHandler(PrintPageHandler);
// Execute the print
printDoc.Print();
}
// Define a method to handle the print page event
static void PrintPageHandler(object sender, PrintPageEventArgs e)
{
// Print page settings and logic can be handled here
e.HasMorePages = false; // Set to true if there are more pages to print
}
}
Imports System
Imports System.Drawing.Printing
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Create a PDF document from a file
Dim pdf = PdfDocument.FromFile("example.pdf")
' Print the PDF using the default printer with dialogue
pdf.Print()
' To print without showing the Windows print dialog, use the overload:
pdf.Print(printerSettings:= New PrinterSettings(), showPrintDialog:= False)
' Alternatively, you can get a PrintDocument object for more options
Dim printDoc As PrintDocument = pdf.GetPrintDocument()
' You can customize the printing settings using the PrintDocument object
' before executing the print
AddHandler printDoc.PrintPage, AddressOf PrintPageHandler
' Execute the print
printDoc.Print()
End Sub
' Define a method to handle the print page event
Private Shared Sub PrintPageHandler(ByVal sender As Object, ByVal e As PrintPageEventArgs)
' Print page settings and logic can be handled here
e.HasMorePages = False ' Set to true if there are more pages to print
End Sub
End Class
The code snippet above demonstrates how to print a PDF document using IronPdf library in .NET. It includes options to print with the default Windows printing dialog or silently, and shows how to utilize the native PrintDocument
object for more advanced printing configurations. Make sure to include a reference to System.Drawing.dll
if you're utilizing the PrintDocument
object for custom settings.