New to Telerik UI for WPF? Download free 30-day trial

Printing

RadPdfViewer allows printing of the document shown in it. The following article describes the available printing methods, as well as how to use the respective for the feature API.

Using UI

RadPdfViewer's sample UI allows you to print the currently shown PDF document with a simple button click. Rad Pdf Viewer Printing 03

The button shown in the above picture is actually bound to the PrintPdfDocumentCommand with the help of the PrintCommandDescriptor, so you can modify the UI to fit your needs.

      <telerik:RadButton Command="{Binding PrintCommandDescriptor.Command}" Visibility="{Binding PrintCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False"> 
        <ToolTipService.ToolTip> 
          <TextBlock Text="Print" /> 
        </ToolTipService.ToolTip> 
        <Image Source="/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/printer.png" Stretch="None" /> 
      </telerik:RadButton> 

More about command descriptors you can find here.

Printing Programmatically

Additionally, to using the UI, you can print by taking advantage of the Print() and Print(PrintSettings printSettings) methods of RadPdfViewer.

The PrintSettings class holds all possible customization options when invoking printing:

  • DocumentName: Specifies the name of the document.

  • PageMargins: Specifies the page margin of the document.

  • UseDefaultPrinter: Forces silent printing to the default printer.

    PrintSettings settings = new PrintSettings() 
    { 
        DocumentName = "My document", 
        PageMargins = new Thickness(50), 
        UseDefaultPrinter = true 
    }; 
 
    this.pdfViewer.Print(settings); 
RadPdfViewer also provides a Print(PrintDialog printDialog, PrintSettings settings) method. It allows you to pass an already initialized PrintDialog instance to the method and print the PDF document shown in the viewer. This means that you have control over the way the document is printed and can, for example, print it silently to a printer other than the default one.

You can download a runnable project showing how you can customize the printing functionality from our online SDK repository on GitHub.

See Also

In this article