You have a few options to open a document using Xamarin.Forms - Document Viewer and Basic Viewer
Before you get started, we recommend you have a look at Microsoft's comprehensive guide on Customizing a ContentPage. It is important that you understand how Xamarin renders the same page on different platforms using ContentPage
, ExportRenderer
and PageRenderer
. In this guide, you will learn how to create a fully featured document viewer and editor as page renderer on each platform.
Complete sample code can be found here:
The rendering process can be taken advantage of to implement platform-specific customization by creating a custom renderer for a ContentPage
on each platform. The process for doing this is as follows:
An unaltered ContentPage
can be added to the shared Xamarin.Forms project, as shown in the following XAML code example:
Similarly, the code-behind file for the ContentPage
should also remain unaltered, as shown in the following code example:
An instance of the AdvancedViewerPage
will be used to display document viewer on each platform. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the AdvancedViewerPage
class.
The empty AdvancedViewerPage
must be displayed by the Xamarin.Forms application. This occurs when a button on the MainPage
instance is tapped, which in turn executes the OnOpenAdvancedViewerButtonClicked
method, as shown in the following code example:
This code simply navigates to the AdvancedViewerPage
, on which custom renderers will customize the page's appearance on each platform.
The AdvancedViewerPage
instance is rendered by platform-specific AdvancedViewerPageRenderer
classes, which all derive from the PageRenderer
class for that platform. This results in each AdvancedViewerPage
instance being rendered with document viewer, as shown in the following GIF:
Android | iOS |
---|---|
The following code example shows the page renderer for the iOS platform:
where the document viewer can be setup as follows:
The following code example shows the page renderer for the Android platform:
where the document viewer can be setup as follows:
Click here for DocumentView
class implementation.
The document viewer is highly customizable and can be configured to remove/modify many components.
Try out the complete sample here: https://github.com/ApryseSDK/xamarin-forms-sample.
If you are looking for a quick start on displaying documents in your application, please first take a look at the document viewer guide as it contains all out of box controls to provide you with the best viewing and annotating experience. Continue reading this article if you are looking for embedding viewer component alone.
Before you get started, we recommend you have a look at Microsoft's comprehensive guide on Customizing a ContentPage. It is important that you understand how Xamarin renders the same page on different platforms using ContentPage
, ExportRenderer
and PageRenderer
. In this guide, you will learn how to create the PDFViewCtrl
page renderer on each platform.
Complete sample code can be found here:
The rendering process can be taken advantage of to implement platform-specific customization by creating a custom renderer for a ContentPage
on each platform. The process for doing this is as follows:
An unaltered ContentPage
can be added to the shared Xamarin.Forms project, as shown in the following XAML code example:
Similarly, the code-behind file for the ContentPage
should also remain unaltered, as shown in the following code example:
The following code example shows how the page can be created in C#:
An instance of the ViewerPage
will be used to display PDF file on each platform. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the ViewerPage
class.
The empty ViewerPage
must be displayed by the Xamarin.Forms application. This occurs when a button on the MainPage
instance is tapped, which in turn executes the OnOpenViewerButtonClicked
method, as shown in the following code example:
This code simply navigates to the ViewerPage
, on which custom renderers will customize the page's appearance on each platform.
The ViewerPage
instance is rendered by platform-specific ViewerPageRenderer
classes, which all derive from the PageRenderer
class for that platform. This results in each ViewerPage
instance being rendered with a PDF file, as shown in the following screenshots:
Android | iOS | UWP |
---|---|---|
The following code example shows the page renderer for the iOS platform:
The following code example shows the page renderer for the Android platform:
The following code example shows the page renderer for UWP:
Try out the complete sample here: https://github.com/ApryseSDK/xamarin-forms-sample.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales