Edit this page

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 to the default printer.

Using UI

Rad Rich Text Box Printing 01

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.

As of Q3 2013 RadRichTextBox also provides a Print(PrintDialog printDialog, PrintSettings printSettings) method. The method requires you to initialize the dialog first. This means that you could easily print silently to a printer different from the default one or modify other settings.

You can download a runnable project of this from our online SDK repository here, the example is listed as RichTextBox/CustomizePrinting.

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.

  • UseDefaultPrinter - forces silent printing. The option 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.

  • PageRange - allows you to specify a single page or a range of pages which to be printed.

PrintSettings settings = new PrintSettings()
{
    DocumentName = "My document",
    PrintMode = PrintMode.Native,
    PrintScaling = PrintScaling.None,
    UseDefaultPrinter = true,
    PageRange = new PageRange(2, 4)
};

this.radRichTextBox.Print(settings);
Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy