# 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 loaded in a `RadRichTextBox` control added to the visual tree of the WPF application. If the editor shouldn't be visible for the end-user, you can set its `Height` property to 0.

The printing feature uses the .NET native printing APIs.

## Using UI

![Rad Rich Text Box Printing 01](https://www.telerik.com/products/wpf/documentation/assets/1931b914dcdcb35eb5e50ff79ec38773/radrichtextbox_printing_01.png)

RadRichTextBox's predefined UI – [RadRichTextBoxRibbonUI](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/ui-for-applying-rich-text-formatting/features-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**:

```XAML
    <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`.

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.

> important You can download a runnable project of this from our online SDK repository [here](https://github.com/telerik/xaml-sdk/tree/master/), the example is listed as **RichTextBox/CustomizePrinting**.

```C#
    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.

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

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

    this.radRichTextBox.Print(settings);
```

## Printing to PDF and Virtual Printers

When you need to create a PDF file from a `RadDocument`, it is strongly recommended to use [PdfFormatProvider](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/import-export/pdf/pdfformatprovider) instead of printing to a virtual printer such as **Microsoft Print to PDF**.

Printing via `PrintDialog` passes WPF visual elements through the Windows print spooler (`XpsDocumentWriter` pipeline). Some virtual PDF printer drivers have known limitations when subsetting and embedding certain OpenType/TrueType fonts (such as **Calibri**), which can cause the driver to silently output a 0-byte or corrupted `.pdf` file without raising an exception.

Using `PdfFormatProvider` circumvents the Windows print spooler entirely, producing clean, spec-compliant PDF documents with properly embedded fonts directly from code:

```C#
    PdfFormatProvider provider = new PdfFormatProvider();
    using (Stream output = File.OpenWrite("document.pdf"))
    {
        provider.Export(this.radRichTextBox.Document, output, null);
    }
```

## See Also

* [Using PdfFormatProvider](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/import-export/pdf/pdfformatprovider)
* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/getting-started/getting-started)
* [Knowledge Base Articles](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/kb-articles)
