Print Options

When printing a PDF, DynamicPDF PrintManager provides many options for printing. Access these options through the PrintJob class's PrintOptions property which is a PrintJobPrintOptions class. The following examples illustrate printing a PDF using different print options. Print options can be set for the entire print job or for each page within the print job.

PrintJob.PrintOptions Property

A PrintJob has a PrintOptions property. This property provides an underlying PrintJobPrintOptions class. The easiest way to access a print job's options is through the PrintJob.PrintOptions property.

PrintJobPrintOptions

The PrintJobPrintOptions class provides thirteen properties, including properties such as collating and scaling.

Properties

Collate Gets or sets a value indicating if the job's copies should be collated.
Color Gets or sets a value indicating if the job should printed in color.
Copies Gets or sets a value indicating the number of copies to print.
DuplexMode Gets or sets a value indicating the duplex mode to use when printing the pages.
HorizontalAlign Gets or sets a value indicating the horizontal alignment to use when printing the pages.
MediaType Gets or sets a value indicating the media type to use when printing.
Orientation Gets a value indicating the orientation to use when printing the pages.
PaperSize Gets or sets a value indicating the size of paper to use when printing the pages.
PaperSource Gets or sets a value indicating the paper source (tray) to use when printing.
PrintAnnotations Gets or sets a value indicating if annotations from the PDF should be printed.
Resolution Gets or sets a value indicating the resolution to use when printing.
Scaling Gets or sets a value indicating the page scaling to use when printing the pages.
VerticalAlign Gets or sets a value indicating the vertical alignment to use when printing the pages.

Methods

Dispose() Clean up any resources being used.
Equals(Object) Determines whether the specified Object is equal to the current Object . (Inherited from Object)
GetHashCode() Serves as a hash function for a particular type. (Inherited from Object)
GetType() Gets the Type of the current instance. (Inherited from Object)
SetMediaTypeByName(String) Sets the media type to use based on its name.
SetPaperSizeByName(String) Sets the size of paper to use based on its name.
SetPaperSourceByName(String) Sets the paper source (tray) to use based on its name.
SetResolutionByDpi(Int32) Sets the resolution to use based on its DPI.
SetResolutionByDpi(Int32, Int32) Sets the resolution to use based on its DPI.
ToString() Returns a String that represents the current Object . (Inherited from Object)

Examples

This example demonstrates how to send a particular PDF document to a printer while setting the document to print two copies, print in color, scale to actual size, and print without annotations.

To set a particular PrintJob option, use the PrintOption's properties (i.e., print job.PrintOptions.Color). If you wish to check if a particular printer supports a specific feature, you can do this by checking the printer's properties (i.e., printJob.Printer.Color). Setting options on an unsupported print job (in the PrintOptions class) causes the specified printer to throw an exception. For example, setting PrintJob.PrintOptions.Color to true when a selected printer does not support color results in a thrown exception.

PrintJob printJob = new PrintJob(Printer.Default, pdfFilePath);

if (printJob.Printer.Color)
    printJob.PrintOptions.Color = true;
    
printJob.PrintOptions.Copies = 2;
printJob.PrintOptions.Scaling = PageScaling.ActualSize; // Can also use AutoPageScaling or PercentagePageScaling objects
printJob.PrintOptions.PrintAnnotations = false;

printJob.Print();       
Dim MyPrintJob As New PrintJob(Printer.Default, pdfFilePath)

If (MyPrintJob.Printer.Color) Then
    MyPrintJob.PrintOptions.Color = True
End If

MyPrintJob.PrintOptions.Copies = 2
MyPrintJob.PrintOptions.Scaling = PageScaling.ActualSize ' Can also use AutoPageScaling or PercentagePageScaling objects
MyPrintJob.PrintOptions.PrintAnnotations = False

MyPrintJob.Print()

Page Level Print Options

This example demonstrates overriding global print options for a specific page within a print job using PrintJobPagePrintOptions class.

Note that the PrintJobPagePrintOptions.Inherit property must be set to false before updating the print options for that page. Not all print options at the global level are available at the page level. Properties such as Color, Copies, Collate, DuplexMode & Resolution are unavailable at the page level. These properties can only be set for an entire print job.

PrintJob printJob = new PrintJob(Printer.Default, pdfFilePath);
//Set the print options for the entire print job.
if (printJob.Printer.Color)
   printJob.PrintOptions.Color = true;
                        
printJob.PrintOptions.Copies = 2;
printJob.PrintOptions.Scaling = PageScaling.ActualSize;
printJob.PrintOptions.PrintAnnotations = false;
                        
//Get the last page and set its print options.
PrintJobPage printJobPage = printJob.Pages[printJob.Pages.Count - 1];
PrintJobPagePrintOptions pagePrintOptions = printJobPage.PrintOptions;
                        
//Set Inherit property to false in order to change the print options for a specific page.
pagePrintOptions.Inherit = false;
pagePrintOptions.Scaling = new PercentagePageScaling(0.5f);
pagePrintOptions.HorizontalAlign = HorizontalAlign.Left;
pagePrintOptions.PrintAnnotations = true;
printJob.Print();        
Dim printJob As New PrintJob(Printer.Default, pdfFilePath)
'Set the print options for the entire print job.
If (printJob.Printer.Color) Then
   printJob.PrintOptions.Color = True
End If
			
printJob.PrintOptions.Copies = 2
printJob.PrintOptions.Scaling = PageScaling.ActualSize
printJob.PrintOptions.PrintAnnotations = False
			
'Get the last page and set its print options.
Dim printJobPage As PrintJobPage = printJob.Pages(printJob.Pages.Count - 1)
Dim pagePrintOptions As PrintJobPagePrintOptions = printJobPage.PrintOptions
			
'Set Inherit property to false in order to change the print options for a specific page.
pagePrintOptions.Inherit = False
pagePrintOptions.Scaling = New PercentagePageScaling(0.5F)
pagePrintOptions.HorizontalAlign = HorizontalAlign.Left
pagePrintOptions.PrintAnnotations = True
printJob.Print()

GitHub

Refer to the print-manager-dotnet-core project on GitHub for examples demonstrating how to use the DynamicPDF PrintManager for .NET. Examples of using print options is provided by the following two files.

In this topic