Click or drag to resize

Printing

The users print from the viewer toolbar. Your application can print for them, with the print dialog or directly on a printer without any dialog. Printing is allowed only when the document permissions allow it (see Security and viewer preferences).

Printing with the print dialog

PrintWithDialog (or Print) shows the print dialog of the viewer, where the user chooses the printer, the pages and the options. The method returns at once.

Printing without a dialog

PrintAsync(Int32, Int32, String) prints a range of pages on a printer you choose - or on the default printer - without any dialog, and tells you when the document has been sent to the printer. The first page is page 1; 0 prints the whole document.

// the whole document on the default printer
bool printed = await pdfViewer.PrintAsync(0, 0, null);

// pages 2 to 5 on a named printer
printed = await pdfViewer.PrintAsync(2, 5, "Office Printer");

A printer chosen by the user with the Windows Forms PrintDialog (its PrinterSettings.PrinterName) or the WPF PrintDialog (its PrintQueue.FullName) can be passed to PrintAsync. The samples show both.

When the document does not allow printing, PrintAsync throws a PdfViewerException.

The methods of the previous versions

PrintAll, PrintAllFit(Boolean), PrintPages(Int32, Int32) and PrintPagesFit(Int32, Int32, Boolean) are kept: they print on the default printer without a dialog and return at once. They count pages from 0, as in the previous versions. A printing error is reported with the LoadError event. Use PrintAsync in new code.

See Also