Telerik blogs
XamarinT Light_870x220

Text selection and link annotations are now part of the Telerik Xamarin PdfViewer control! Explore the powerful new features of our R3 2019 release.

There are some great new capabilities in the latest release of Telerik UI for Xamarin. The text selection and link annotations features will add more interactivity to your PDF documents, enabling end users to select any text from the document and copy it. Link annotations, on the other hand, will allow navigating to an external hyperlink or to another place within the same document. Let’s take a closer look at these features.

Text Selection

Just tap and hold on any text within the PDF document displayed in RadPdfViewer – the text will be highlighted and the two drag handles will enable you to manipulate the selection. In addition, as soon as the selection is made, PdfViewer displays a customizable SelectionMenu with a default Copy command allowing you to retrieve the selected text. A GIF is worth a thousand words, so let's see this capability in action:

xamarin_pdfviewer_textselection

Additionally, RadPdfViewer provides some useful customization capabilities related to text selection, so you can fine-tune the appearance of the selected text, the handles and the selection menu. All these settings can be applied through the SelectionSettings property of RadPdfViewer.

For example. let's modify the colors used for text selection:

<telerikPdfViewer:RadPdfViewer.SelectionSettings>
    <telerikPdfViewer:SelectionSettings
                SelectionIndicatorColor="{StaticResource MainColor}"
                SelectionFill="{StaticResource MainColorTranslucent}" />
    </telerikPdfViewer:RadPdfViewer.SelectionSettings>
</telerikPdfViewer:RadPdfViewer>

Where the referenced StaticResources are defined in a MergedDictionary:

<ResourceDictionary>
    <Color x:Key="MainColor">#FC5173</Color>
    <Color x:Key="MainColorTranslucent">#4DFD8BA2</Color>
    <Style TargetType="telerikPdfViewer:SelectionMenu">
        <Setter Property="Fill" Value="{StaticResource MainColor}" />
    </Style>         
</ResourceDictionary>

And the result on Android and iOS:

PdfViewer Text Selection

By default, the selection menu includes a Copy command which copies the selected text into the clipboard. This setting is, of course, configurable – you can easily add various commands to the menu through the provided flexible API. The SelectionSettings class exposes MenuItems collection of SelectionMenuItem objects, each of them providing Text and Command properties. To learn more about this, please go to the Text Selection documentation topic where an example is also provided.

Link Annotations

R3 2019 ships support for link annotations as well. There are two types of link annotations: annotations that point to absolute URLs, and those that point to a location within the document.

RadPdfViewer is capable of properly treating them both.

In the case with hyperlinks, tapping on the link will have а browser open, navigated to the respective address. Keep in mind this still depends on the platform - we’re using the Device.OpenUri method to navigate to the corresponding URL. In the second case (annotations pointing to bookmarks within the document), upon tap, the view port will be scrolled to the specified destination. This is a particularly useful capability if you have a table of contents at the beginning of the PDF document.

Check out the GIF below to see how RadPdfViewer handles a link annotation that points to a hyperlink:

xamarin_pdfviewer_linkannotations

An extension point for customizing the URL navigation behavior is also available - RadPdfViewer provides LinkAnnotationTapped event that can be used to plug custom logic related to links in the PDF document. Find out more about this in our documentation topic on Link Annotations.

Tell Us What You Think

As always, we would love to hear your feedback about the PdfViewer component and how we can improve it. If you have any ideas for features to add, do not hesitate to share this information with us on our Telerik UI for Xamarin Feedback portal.

Still haven't tried Telerik UI for Xamarin? The free trial is right here waiting for you to give it a try and explore all the components provided in the suite.


YanaKerpecheva
About the Author

Yana Kerpecheva

Yana Kerpecheva is a Senior Technical Support Engineer on the Telerik UI for Xamarin team. She has been working with Telerik products since 2008, when she joined the company. Apart from work, she likes skiing and travelling to new places.

Related Posts

Comments

Comments are disabled in preview mode.