Commands

RadPdfViewer provides the following commands of type ICommand:

  • ZoomInCommand
  • ZoomOutCommand
  • FitToWidthCommand
  • NavigateToNextPageCommand
  • NavigateToPreviousPageCommand
  • NavigateToPageCommand
  • ToggleLayoutModeCommand: Triggers the RadPdfViewer LayoutModes (ContinuousScroll and SinglePage)

The RadPdfViewer Toolbar exposes the above commands built-in. For more information please check the PdfViewer Toolbar article.

Example

Following is an example how the RadPdfViewer commands could be called on a button click action. For the example we will visualize a pdf document from stream.

First, add a pdf document to the project and set its build action to be EmbeddedResource.

Then, add the following code to visualize the document:

Assembly assembly = typeof(Commands).Assembly;
string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("pdfviewer-overview.pdf"));
this.pdfViewer.Source = assembly.GetManifestResourceStream(fileName);

Finally, use the following snippet to declare a RadPdfViewer in XAML and add a few buttons that will execute the pdf viewer commands:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <telerikCommon:RadUniformGrid>
        <Button Text="Zoom In"
                Command="{Binding Source={x:Reference pdfViewer}, Path=ZoomInCommand}" />
        <Button Text="Zoom Out"
                Command="{Binding Source={x:Reference pdfViewer}, Path=ZoomOutCommand}" />
        <Button Text="Fit To Width"
                Command="{Binding Source={x:Reference pdfViewer}, Path=FitToWidthCommand}" />
        <Button Text="Previous Page"
                Command="{Binding Source={x:Reference pdfViewer}, Path=NavigateToPreviousPageCommand}" />
        <Button Text="Next Page"
                Command="{Binding Source={x:Reference pdfViewer}, Path=NavigateToNextPageCommand}" />
    </telerikCommon:RadUniformGrid>
    <telerikPdfViewer:RadPdfViewer x:Name="pdfViewer"
                                   Grid.Row="1"
                                   MinZoomLevel="0.3"
                                   MaxZoomLevel="4"/>
</Grid>

Where the telerikPdfViewer namespace is the following:

xmlns:telerikPdfViewer="clr-namespace:Telerik.XamarinForms.PdfViewer;assembly=Telerik.XamarinForms.PdfViewer"

A sample Commands example can be found in the PdfViewer/Features folder of the SDK Samples Browser application.

See Also

In this article
Not finding the help you need? Improve this article