Key Features

The purpose of this help article is to show you the key features of the RadPdfViewer control.

Pdf Documment Visualization

RadPdfViewer control enables you to visualize Pdf documents through the following property:

  • Source(DocumentSource): Defines the source of the document.

The Pdf Document could be loaded from:

  • FixedDocument
private void ImportFixedDocument()
{
    Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
    Assembly assembly = typeof(KeyFeatures).Assembly;
    string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("pdfviewer-overview.pdf"));
    using (Stream stream = assembly.GetManifestResourceStream(fileName))
    {
        RadFixedDocument document = provider.Import(stream);
        this.pdfViewer.Source = document;
    }
}

or

private void ImportFixedDocument()
{
    Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
    Assembly assembly = typeof(KeyFeatures).Assembly;
    string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("pdfviewer-overview.pdf"));
    using (Stream stream = assembly.GetManifestResourceStream(fileName))
    {
        RadFixedDocument document = provider.Import(stream);
        this.pdfViewer.Source = new FixedDocumentSource(document);
    }
}
  • Uri
Uri uri = this.GetUri();
this.pdfViewer.Source = uri;

or

Uri uri = this.GetUri();
this.pdfViewer.Source = new UriDocumentSource(uri);
  • File

From R1 2019 SP the RadPdfViewer supports FileDocumentSouce.

You can visualize the pdf document from a file located on a device.

In order to make sure that the file exists on the device you could use the following code:

System.IO.File.OpenRead(path)

where the path is a sting that contains the path to the file location.

Please make sure that you have granted the app all the permissions needed before the resources are used. Otherwise, an error will be raised.

  • Byte Array
byte[] bytes = this.GetBytes();
this.pdfViewer.Source = bytes;

or

byte[] bytes = this.GetBytes();
this.pdfViewer.Source = new ByteArrayDocumentSource(bytes, true);          
  • Stream
Assembly assembly = typeof(KeyFeatures).Assembly;
string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("pdfviewer-overview.pdf"));
Stream stream = assembly.GetManifestResourceStream(fileName);
this.pdfViewer.Source = stream;

Zoom Level Support

RadPdfViewer exposes properties for applying min and max zoom values.

  • MaxZoomLevel(double): Defines the maximum magnification factor at which content could be maximized. The default value is 3.0
  • MinZoomLevel(double): Defines the minimum magnification factor at which content could be minimized. The default value is 0.3

In order to check how these properties works you should set the ZoomIn and ZoomOut Commmands of the control. For more details please check the Commands article.

Viewing Modes

You could easily set one of the two layout modes that the control provides through its LayoutMode property.

The available options are:

  • ContinuousScroll: Displays pages in a continuous vertical column.
  • SinglePage: Displays one page at a time.

By default the PdfViewer LayoutMode property is set to ContinuousScroll.

The RadPdfViewer LayoutMode could be triggered through the ToggleLayoutModeCommand and the ToggleLayoutModeToolbarItem.

Here is how the PdfViewer looks when LayoutMode is set to ContinuousScroll:

PdfViewer ContinuousScroll

And when the LayoutMode property is set to SinglePage:

PdfViewer SinglePage

Page Spacing

  • PageSpacing(double): Defines the space between the pages of the Pdf Document. The default value is 20.0

PagesStart Index

  • VisiblePagesStartIndex(int): Defines the index at which the document will be displayed. The default value is 0.

BusyIndicator Template

If the default busy template does not suit your needs, you could easily define a custom template through the following property:

  • BusyIndicatorTemplate(DataTemplate): Specifies the template visualized while the Pdf Document is loading.

Here is an example how the custom BusyIndicatorTemplate could be defined:

<telerikPdfViewer:RadPdfViewer x:Name="pdfViewer">
    <telerikPdfViewer:RadPdfViewer.BusyIndicatorTemplate>
        <DataTemplate>
            <telerikPrimitives:RadBusyIndicator AnimationType="Animation10"
                                                AnimationContentHeightRequest="100"
                                                AnimationContentWidthRequest="100"
                                                IsBusy="True" />
        </DataTemplate>
    </telerikPdfViewer:RadPdfViewer.BusyIndicatorTemplate>
</telerikPdfViewer:RadPdfViewer>

Here is how the BusyIndicator Template looks:

PdfViewer BusyIndicator Template

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

Example

Here is an example how the above RadPdfViewer features could be applied:

For the example we will visualize a pdf document from file embedded in the application with a BuildAction:EmbeddedResource.

Then add the following code to load the pdf document from Stream:

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

Finally, use the following snippet to declare a RadPdfViewer in XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <telerikPdfViewer:RadPdfViewerToolbar PdfViewer="{Binding Source={x:Reference pdfViewer}}">
        <telerikPdfViewer:ZoomInToolbarItem />
        <telerikPdfViewer:ZoomOutToolbarItem />
        <telerikPdfViewer:ToggleLayoutModeToolbarItem />
    </telerikPdfViewer:RadPdfViewerToolbar>
    <telerikPdfViewer:RadPdfViewer x:Name="pdfViewer"
                                   Grid.Row="1"
                                   PageSpacing="15"
                                   MinZoomLevel="0.2"
                                   MaxZoomLevel="5" />
</Grid>

Where the telerikPdfViewer namespace is the following:

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

A sample Key Features 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