New to Telerik UI for .NET MAUI? Start a free 30-day trial


PDF Viewer provides the following commands of type ICommand:

  • ZoomInCommand—Zooms in.
  • ZoomOutCommand—Zooms out.
  • NavigateToNextPageCommand—Navigates to next page.
  • NavigateToPreviousPageCommand—Navigates to previous page.
  • NavigateToPageCommand—Navigates to a concrete page.
  • ToggleLayoutModeCommand—Triggers the RadPdfViewer LayoutModes (ContinuousScroll and SinglePage).
  • FitToWidthCommand—There are two options when executing FitToWidth command:

    • FitDocumentToWidthCommand(default)—Refers to the entire document; this option will look up the widest of all pages and set a zoom level allowing this page's width to fit.

      If the document has pages with different widths, when you view a page that is not the widest, this page will not occupy all available horizontal space.

    • FitPageToWidthCommand—Executes the FitToWidth command for the current page and disregards the width of the other pages in the document.

  • DoubleTappedCommand—This command is triggerd by the user when double-tapping the content area of the PDF Viewer. On the first double-tap, the document is zoomed 2.5 times at the tapped location, another double-tap triggers the FitToWidth command.

PDF Viewer's toolbar contains some of the commands as built-in options so you can use them though the predefined items in the toolbar. For more information, check the PDF Viewer Toolbar article.

Example: Using the PDF Viewer Commands

The following example shows how to call RadPdfViewer commands on a button click action. The snippet below shows only one of the available approaches for loading a PDF document.

1. Add a PDF document to the project and set its build action to EmbeddedResource.

2. Add the following code to visualize the document:

Func<CancellationToken, Task<Stream>> streamFunc = ct => Task.Run(() =>
    Assembly assembly = typeof(Commands).Assembly;
    string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("pdf-overview.pdf"));
    Stream stream = assembly.GetManifestResourceStream(fileName);
    return stream;
this.pdfViewer.Source = streamFunc;

3. Use the following snippet to declare a RadPdfViewer in XAML and add a few buttons that will execute the PDF Viewer commands:

<Grid RowDefinitions="Auto, *">
        <Button Text="Zoom In"
                Command="{Binding Source={x:Reference pdfViewer}, Path=ZoomInCommand}"
                Margin="0, 0, 10, 10" />
        <Button Text="Zoom Out"
                Command="{Binding Source={x:Reference pdfViewer}, Path=ZoomOutCommand}"
                Margin="0, 0, 10, 10" />
        <Button Text="Fit To Width"
                Command="{Binding Source={x:Reference pdfViewer}, Path=FitToWidthCommand}"
                Margin="0, 0, 10, 10" />
        <Button Text="Previous Page"
                Command="{Binding Source={x:Reference pdfViewer}, Path=NavigateToPreviousPageCommand}"
                Margin="0, 0, 10, 10" />
        <Button Text="Next Page"
                Command="{Binding Source={x:Reference pdfViewer}, Path=NavigateToNextPageCommand}"
                Margin="0, 0, 10, 10" />
        <Button Text="Toggle Layout Mode"
                Command="{Binding Source={x:Reference pdfViewer}, Path=ToggleLayoutModeCommand}"
                Margin="0, 0, 10, 10" />
    <telerik:RadPdfViewer x:Name="pdfViewer"
                          MaxZoomLevel="4" />

By default , the FitToWidth command of the PDF Viewer is assigned to the "Fit Document to Width" option. To switch to the "Fit Page to Width" option, set the FitToWidthCommand property of RadPdfViewer to FitPageToWidthCommand:

this.pdfViewer.FitToWidthCommand = new PdfViewerFitPageToWidthCommand();

Calling the FitToWidthCommand on a button click action, as in the example above, executes "Fit Page to Width" on the current page.

For a runnable example demonstrating the PDF Viewer commands, see the SDKBrowser Demo Application and go to PdfViewer > Commands.

See Also

In this article