Overview

The DynamicPDF PrintManager API is straightforward yet still provides a rich feature for printing PDF documents. When using the PrintManager API, you can make your applications as straightforward or complex as desired. Developers new to the component will find that understanding the object model comes quickly, while adding PDF printing functionality to your .NET application has never been easier.

Understanding DynamicPDF PrintManager API requires understanding three primary classes; the PrintJob class, the Printer class, and the PrintOptions class.

The PrintJob Class

The PrintJob class is the main class required to use the PrintManager API. Use this class to:

The following is a simple example using the PrintJob class to print a PDF.

PrintJob printJob = new PrintJob(Printer.Default, Util.GetPath("Resources/DocumentA.pdf"));
printJob.Print();

Constructor

The PrintJob Class has ten constructors that allow initializing a PrintJob by specifying the printer, the input PDF, and the input PDF's pages to print.

public PrintJob(Printer printer)
public PrintJob(Printer printer, InputPdf inputPdf)
public PrintJob(Printer printer, InputPdf inputPdf, int startPage, int pageCount)
public PrintJob(Printer printer, string pdfFileName)
public PrintJob(Printer printer, string pdfFileName, int startPage, int pageCount)
public PrintJob(string printerName)
public PrintJob(string printerName, InputPdf inputPdf)
public PrintJob(string printerName, InputPdf inputPdf, int startPage, int pageCount)
public PrintJob(string printerName, string pdfFileName)
public PrintJob(string printerName, string pdfFileName, int startPage, int pageCount)

Properties

The PrintJob class has the following properties.

DocumentName Gets or sets the name of the document that is to be shown in the print spooler.
JobId Gets the ID of the job.
Pages Gets a PrintJobPageList object that represents the pages to be printed by the job.
PagesPrinted Gets a value indicating how many pages have been printed.
Printer Gets the Printer object that is targeted by the job.
PrintOptions Gets a PrintJobPrintOptions objects that represents the printing options for the job.
PrintPriority Gets or sets the Print priority of print job. Enter the value in between the Range(1 - 99).
PrintToFileName Gets or sets the filename or path where the output will be saved.
RawStatus RawStatus represents the status as returned by the printer driver. It may have multiple bits set at the same time which means it can represent multiple values from the PrintJobStatus enumeration.
Status Gets the current status of the job.

Methods

The PrintJob class has the following methods.

AddLicense(String) Adds a license key.
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)
Print() Prints the job to the printer.
ToString() Returns a String that represents the current Object . (Inherited from Object)

Events

The PrintJob supports the following events.

PrintJob.Failed Occurs when a job fails.
PrintJob.Starting Occurs before starting a job.
PrintJob.Succeeded Occurs when a job succeeds.
PrintJob.Updated Occurs when a job's status or pages printed is updated.

The Printer Class

Use the Printer class to determine a specified printer's supported features and functions. The Printer class does not typically need to be instantiated individually but can be accessed directly as a property of the PrintJob class. The Printer class properties are read-only and show a specific printer capability. For instance, you can tell if a printer can print in color if a printer supports a duplex, or what paper sizes are available. Reading the Printer properties is similar to opening the printer's properties dialog box to see what is or is not available for that printer.

Properties

The Printer class has the following properties.

Collate Gets a value indicating if the printer supports collating.
Color Gets a value indicating if the printer supports color printing.
Default Gets the system's default printer.
DriverName Gets the name of the printer driver.
DriverVersion Gets the version of the printer driver.
Duplex Gets a value indicating if the printer supports duplex printing.
Fax Gets a value indicating if the printer supports fax printing.
MaxCopies Gets the maximum number of copies supported by the printer.
MaxPaperHeight Gets the maximum paper height supported by the printer in typesetting points.
MaxPaperWidth Gets the maximum paper width supported by the printer in typesetting points.
MediaTypes Gets a MediaTypeList object that represents the available media types for the printer.
MinPaperHeight Gets the minimum paper height supported by the printer in typesetting points.
MinPaperWidth Gets the minimum paper width supported by the printer in typesetting points.
Name Gets the name of the printer.
PaperSizes Gets a PaperSizeList object that represents the available paper sizes for the printer.
PaperSources Gets a PaperSourceList object that represents the available paper sources (trays) for the printer.
Resolutions Gets a ResolutionList object that represents the available resolutions for the printer.

Methods

The Printer class has the following methods.

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)
GetLocalPrinters() Returns an array of the system's local printers.
GetType() Gets the Type of the current instance. (Inherited from Object)
Refresh() Reinitializes the printer properties in order to update any newly aaded custom paper source, size or any such customizable properties.
ToString() Returns a String that represents the current Object . (Inherited from Object)

The PrintJobPrintOptions Class

The PrintJobPrintOptions class is accessed through the PrintJob class's PrintOptions property (PrintJob.PrintOptions). The PrintOptions class sets the specific options PrintJob uses to send a PDF document(s) to the printer.

Use PrintOptions to specify options such as a particular duplex mode to use (if supported by your printer), the orientation or scaling of a print job and other options. Setting the PrintOptions is the programmatic equivalent of selecting specific options from the print dialog box when manually sending a file to the printer.

Properties

The PrintJobPrintOptions class has the following 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

The PrintJobPrintOptions has the following 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)

Example

The following code illustrates using PrintJob, Printer, and PrintJobPrintOptions. It shows sending a PDF document to the default printer, checking to see if that printer supports duplex printing, and setting a print job to print in vertical duplex mode.

PrintJob printJob = new PrintJob(Printer.Default, "C:\\Temp\\Print.pdf");
if (printJob.Printer.Duplex)
    printJob.PrintOptions.DuplexMode = DuplexMode.DuplexVertical;
printJob.Print();
Dim MyPrintJob As New PrintJob(Printer.Default, "C:\\Temp\\Print.pdf")
If (MyPrintJob.Printer.Duplex) Then
    MyPrintJob.PrintOptions.DuplexMode = DuplexMode.DuplexVertical
End If
MyPrintJob.Print()

GitHub

Refer to the print-manager-dotnet-core project on GitHub for examples demonstrating how to use the DynamicPDF PrintManager for .NET.

In this topic