Determining Printer Capabilities
The Printer class represents a physical or virtual printer and serves as the interface between a print job and the actual printer device. When printing, you use this class to obtain a list of available printers and to query a printer’s capabilities, such as supported paper sizes, trays, resolutions, duplexing, and color support. This allows you to verify that the printer supports the required functionality before submitting the print job.
When creating a printer you can pass the printer's name in the constructor or use your system's default printer (see Simple Printing).
Available Printers
Obtain a list of available printers using the Printer.GetLocalPrinters method.
foreach (Printer printer in Printer.GetLocalPrinters())
Console.WriteLine(printer.Name);
For Each printer As Printer In Printer.GetLocalPrinters()
Console.WriteLine(printer.Name)
Next
[AvailablePrintersExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/AvailablePrintersExample.cs){#gitlink-id target=_blank}
[AvailablePrintersExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/AvailablePrintersExample.vb){#gitlink-id target=_blank}
If a printer is not available, then a print job will throw a ceTe.DynamicPDF.Printing.PrintingException.
Printer Capabilities
Not all printers support the same printing capabilities. Attempting to use an unsupported printer setting can result in a run-time error or undefined behavior. The Printer class provides a set of properties that allow applications to query a printer’s supported capabilities before applying print settings such as duplex printing, color printing, paper sizes, paper trays, media types, and resolutions.
public static void Run()
{
PrintJob printJob = new PrintJob(Printer.Default);
Console.WriteLine("Options for: " + printJob.Printer.Name);
Console.WriteLine("Collate " + printJob.Printer.Collate);
Console.WriteLine("Duplex " + printJob.Printer.Duplex);
Console.WriteLine("MaxCopies " + printJob.Printer.MaxCopies);
Console.WriteLine("MaxPaperHeight " + printJob.Printer.MaxPaperHeight);
Console.WriteLine("MaxPaperWidth " + printJob.Printer.MaxPaperWidth);
Console.WriteLine("MinPaperHeight " + printJob.Printer.MinPaperHeight);
Console.WriteLine("MinPaperWidth " + printJob.Printer.MinPaperWidth);
ListPaperSizes(printJob.Printer.PaperSizes);
ListPaperSources(printJob.Printer.PaperSources);
ListResolutions(printJob.Printer.Resolutions);
}
static void ListPaperSizes(PaperSizeList paperSizes)
{
Console.WriteLine("List of Paper Sizes: ");
for (int i = 0; i < paperSizes.Count; i++)
{
Console.WriteLine(" " + paperSizes[i].Name + " : Width= " + UnitConverter.PointsToInches(paperSizes[i].Width) + " : Height = " + UnitConverter.PointsToInches(paperSizes[i].Height));
}
}
static void ListPaperSources(PaperSourceList paperSources)
{
Console.WriteLine("List of Paper Sources ");
for (int i = 0; i < paperSources.Count; i++)
{
Console.WriteLine(" " + paperSources[i].Name);
}
}
static void ListResolutions(ResolutionList resolutions)
{
Console.WriteLine("List of Resolution ");
for (int i = 0; i < resolutions.Count; i++)
{
Console.WriteLine(" " + resolutions[i].HorizontalDpi + " dpi " + resolutions[i].VerticalDpi + " dpi");
}
}
Public Shared Sub Run()
Dim MyPrintJob As PrintJob = New PrintJob(Printer.Default)
Console.WriteLine("Options for: " + MyPrintJob.Printer.Name)
Console.WriteLine("Collate " + MyPrintJob.Printer.Collate.ToString())
Console.WriteLine("Duplex " + MyPrintJob.Printer.Duplex.ToString())
Console.WriteLine("MaxCopies " + MyPrintJob.Printer.MaxCopies.ToString())
Console.WriteLine("MaxPaperHeight " + MyPrintJob.Printer.MaxPaperHeight.ToString())
Console.WriteLine("MaxPaperWidth " + MyPrintJob.Printer.MaxPaperWidth.ToString())
Console.WriteLine("MinPaperHeight " + MyPrintJob.Printer.MinPaperHeight.ToString())
Console.WriteLine("MinPaperWidth " + MyPrintJob.Printer.MinPaperWidth.ToString())
ListPaperSizes(MyPrintJob.Printer.PaperSizes)
ListPaperSources(MyPrintJob.Printer.PaperSources)
ListResolutions(MyPrintJob.Printer.Resolutions)
End Sub
Shared Sub ListPaperSizes(paperSizes As PaperSizeList)
Console.WriteLine("List of Paper Sizes: ")
For i As Integer = 0 To paperSizes.Count - 1
Console.WriteLine(" " & paperSizes(i).Name & " : Width= " & UnitConverter.PointsToInches(paperSizes(i).Width.ToString()) & " : Height = " & UnitConverter.PointsToInches(paperSizes(i).Height.ToString()))
Next
End Sub
Shared Sub ListPaperSources(paperSources As PaperSourceList)
Console.WriteLine("List of Paper Sources ")
For i As Integer = 0 To paperSources.Count - 1
Console.WriteLine(" " & paperSources(i).Name)
Next
End Sub
Shared Sub ListResolutions(resolutions As ResolutionList)
Console.WriteLine("List of Resolution ")
For i As Integer = 0 To resolutions.Count - 1
Console.WriteLine(" " & resolutions(i).HorizontalDpi.ToString() & " dpi " & resolutions(i).VerticalDpi.ToString() & " dpi")
Next
End Sub
[ReadPrinterDetails.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/ReadPrinterDetails.cs){#gitlink-id target=_blank}
[ReadPrinterDetails.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/ReadPrinterDetails.vb){#gitlink-id target=_blank}