Printing

RadRichTextBox allows printing the RadDocument instance shown in it. The following article describes the available printing modes, as well as how to use the respective for the feature API.

In order to take advantage of the printing functionality, the document you want to be printed has to be shown in a RadRichTextBox added to the Visual Tree. In cases when you do not wish to actually show the editor to the user you can set the height of the control to 0.

PrintModes

These are the currently supported PrintModes:

  • Native - uses the default for the system print dialog. The option also allows printing silently in OOB applications with elevated trust to the default printer.

  • Html - exports the document in RadRichTextBox to HTML format using HtmlFormatProvider and passes the exported document to the browser printing mechanism.

    The option does not work in OOB applications.

  • HtmlPreview - exports the document in RadRichTextBox to HTML format using HtmlFormatProvider and passes the exported document to a new browser window which shows a Print and a Close buttons along with the document. The Print button invokes the browser printing mechanism.

    The option does not work in OOB applications.

Html printing was introduced as a way to overcome a performance hit in Silverlight 4. In Silverlight 5 no such issue is observe, thus the recommend PrintMode is Native (Silverlight vector) printing. However, issues may arise with certain printers related to printer settings, drivers and PostScript support. In such cases, forcing Silverlight 4 (bitmap) printing usually resolves the problem. More information on PrintSettings can be found here.

Using UI

Rad Rich Text Box Printing 02

RadRichTextBox's predefined UI – RadRichTextBoxRibbonUI, allows you to choose one of the above-mentioned options from the Print backstage item of the ribbon. The buttons shown on the above picture are actually bound to the PrintCommand, so you can modify the UI to fit your needs.

In order to successfully execute the PrintCommand you have to pass the wanted print mode as a CommandParameter:

<telerik:RadRibbonButton Content="Print" DataContext="{Binding Commands, ElementName=radRichTextBox}"  
  CommandParameter="Native" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding PrintCommand}" /> 

Printing programatically

Additionally to using the UI, you can print by taking advantage of the Print(string documentName, PrintMode mode) and Print(PrintSettings printSettings) methods of RadRichTextBox.

In the respective method, the PrintMode corresponds to the mode in which you wish to print:

this.radRichTextBox.Print("My document", PrintMode.Native); 

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

  • DocumentName - specifies the name of the document.

  • PrintMode - the enumeration allows to select one of the predefined options PrintModes.

  • PrintScaling - specifies whether the content of the document should shrink to page size if needed. The option is relevant for Native print mode only and by default content is shrunk to page size.

  • HtmlPrintExportSettings - when using Html or HtmlPreview printing, HtmlFormatProvider is used and it is possible to specify its export settings. More on import/export settings can be found here

  • UseDefaultPrinter - forces silent printing. Can only be used in OOB application with elevated trust and is only relevant for Native printing mode.

  • ForceVector - forces vector printing in Silverlight 5. Its default value is true. If set to false, tries to execute vector printing and in case it fails the “old” bitmap printing is executed.

PrintSettings settings = new PrintSettings() 
{ 
    DocumentName = "My document", 
    PrintMode = PrintMode.Html, 
    UseDefaultPrinter = true, 
    ForceVector = true 
}; 
this.radRichTextBox.Print(settings); 
In this article