# Custom Document Presenter

Document presenters in **RadPdfViewer** are responsible for displaying the pages of a PDF document, as well as navigating the file and manipulating it. There are two presenters that come out-of-the-box and you can find more information about them  [here](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/ui/document-presenters).

Additionally, **RadPDFViewer** offers you the ability to create your own document presenter, which helps you design the presentational functionality of the document as you want.

This article covers the following topics:

* [Implementing the IFixedDocumentPresenter Interface](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/customization-and-extensibility/custom-document-presenter#implementing-the-ifixeddocumentpresenter-interface)

* [Inheriting FixedDocumentPresenterBase](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/customization-and-extensibility/custom-document-presenter#inheriting-fixeddocumentpresenterbase)

* [Creating a Custom Presenter](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/customization-and-extensibility/custom-document-presenter#creating-a-custom-presenter)

## Implementing the IFixedDocumentPresenter Interface

Implementing this interface allows you to create a fully functioning document presenter in **RadPdfViewer**. The interface contains the following members:

* **Owner**: Тhis property is of type **Telerik.Windows.Documents.UI.IFixedDocumentViewer** and is implemented by **RadPdfViewer**. The owner of your document presenter is the instance of **RadPdfViewer** that uses the presenter.

* **PointerHandlersController:** This property is of type  **Telerik.Windows.Documents.Fixed.UI.PointerHandlers.PointerHandlersController** and the member is responsible for the behavior of **RadPdfViewer** after mouse or touch events.

* **CurrentPage:** The property gets the current RadFixedPage.

* **ShowSelectionMarkers():** The method shows the selection markers.

* **HideSelectionMarkers():** The method hides the selection markers.

* **GetLocationFromViewPoint(Point viewpoint, out RadFixedPage page, out Point location):** This method obtains the page and document location from the provided view point.

* **GetViewPointFromLocation(RadFixedPage page, Point location, out Point viewpoint):** This method obtains the view point from the provided page and document location.

* **PageUp():** This method navigates to the previous page.

* **PageDown():** This method navigates to the next page.

* **GoToPage (int pageNumber):** This method navigates to the provided page number.

* **GoToDestination(Destination destination):** This method navigates to the provided destination.

* **InvalidateMeasure():** This method invalidates the measurement state.

* **InvalidateArrange():** This method invalidates the arrangement state.

* **UpdatePresenterLayout():** This method updates the presenter layout.

* **Initialize(IFixedDocumentViewer owner):** This method initializes the document presenter with the provided owner.

* **Initialize(IFixedDocumentViewer owner, IFixedDocumentPresenter presenter):** This method initializes the document presenter with the provided owner and another document presenter.

* **Release():** This method releases the resources used by the document presenter.

* **CurrentPageChanged:** This event is fired when the current page is changed.

## Inheriting FixedDocumentPresenterBase

The [**FixedDocumentPresenterBase**](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.ui.fixeddocumentpresenterbase) class implements all the members from [**IFixedDocumentPresenter**](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.ui.ifixeddocumentpresenter) but it allows the inheriting class to override those members with custom functionality. Some members of this class are abstract and need to be overridden in the inheriting classes:

* **PagesLayoutManager:** The property is of type **Telerik.Windows.Documents.Fixed.Layout.PagesLayoutManagerBase**  and is responsible for the way pages are laid out in the document.

* **CurrentNo:** The number of the current page.

* **GetLocationFromViewPoint(Point viewpoint, out RadFixedPage page, out Point location):** This method obtains the document location from the provided view point.

* **UpdateScrollOffsetFromPosition(TextPosition position):** This method updates the scroll offset from the provided position.

**PagesLayoutManagerBase** is an abstract class responsible for the layout of the document pages. The class provides the following abstract members:

* **UpdateLayout(Size viewportSize):** This method updates the page layout based on the provided view port.

* **GetPagesLayoutInfos():** This method returns a collection of the layout information for all the pages in the document.

* **Release():** This method releases the resources of the layout manager.

## Creating a Custom Presenter

The following steps illustrate what you need to do to create and register a custom document presenter:

**Step 1:** Create a class that inherits the abstract [**FixedPageLayoutInfo**](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.fixed.layout.fixedpagelayoutinfo) class. This class is responsible for the page layout and should hold information about how to visualize a single page. Implement the base constructor and add your preferences.

**Example 1: Implement FixedPageLayoutInfo**

```C#
public class SinglePageInfo : FixedPageLayoutInfo
{
    public SinglePageInfo(Telerik.Windows.Documents.Fixed.Model.RadFixedPage page, System.Windows.Rect positionInView)
        : base(page, positionInView)
    {
        //...
    }
}
```

**Step 2:** Create a class that inherits the abstract [**PagesLayoutManagerBase**](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.fixed.layout.pageslayoutmanagerbase) class, and will be responsible for the layout of the document pages. Implement all abstract members of the class and override them according to your scenario.

**Example 2: Implement PagesLayoutManagerBase**

```C#
public class SinglePageLayoutManager : PagesLayoutManagerBase
{
    private SinglePageInfo visiblePage;
    private readonly List<SinglePageInfo> pageLayoutInfos;

    public SinglePageLayoutManager(IFixedDocumentPresenter presenter)
        : base(presenter)
    {
        this.pageLayoutInfos = new List<SinglePageInfo>();
    }

    protected override List<FixedPageLayoutInfo> GetPagesLayoutInfos()
    {
        List<FixedPageLayoutInfo> result = new List<FixedPageLayoutInfo>();
        foreach (var info in this.pageLayoutInfos)
        {
            result.Add(info);
        }

        return result;
    }

    public override void Release()
    {
        // Release pageLayoutInfos here.
    }

    public override void UpdateLayout(Size viewportSize)
    {
        // Update pageLayoutInfos here.
    }
}
```

**Step 3:** Add a new class for your custom presenter that inherits the abstract [**FixedDocumentPresenterBase**](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.ui.fixeddocumentpresenterbase) class which, in turn, inherits the **IFixedDocumentPresenter** interface.

**Step 4:** Implement all the members of the **FixedDocumentPresenterBase** class to create a fully functional document presenter. Some members of the FixedDocumentPresenterBase class are abstract and need to be overridden with custom functionality.

> To ensure that the content is loaded, verify that the **VisiblePages** property of FixedDocumentPresenterBase is set every time the visible pages in the presenter are changed.

**Step 5:** Register the custom document presenter as demonstrated in **Example 3**.

**Example 3: Register a custom document presenter**

```C#
this.pdfViewer.RegisterPresenter("CustomPresenterName", new CustomSinglePagePresenter());
```

> tip You can download an example that demonstrates how to create and register a custom document presenter from  [our SDK repository on GitHub](https://github.com/telerik/xaml-sdk/blob/master/PdfViewer/CustomPresenter).

## See Also

* [Document Presenter](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/ui/document-presenters)
