This quick start will guide you through the steps of adding FlexViewer control to the application, binding it with a document source, i.e., GcPdf, and loading the PDF in the FlexViewer control.
To achieve it, follow these steps:
The following image shows how the FlexViewer control appears after completing the steps above.
QuickStart.xaml
) to your Mobile App (Xamerin.Forms) and include references as shown below.XAML |
Copy Code
|
---|---|
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:FlexViewerXamarin" xmlns:c1="http://schemas.grapecity.com/xf/2019/xaml" x:Class="FlexViewerXamarin.QuickStart"> </ContentPage> |
XAML |
Copy Code
|
---|---|
<c1:FlexViewer x:Name="flexViewer"/> |
C# |
Copy Code
|
---|---|
using Xamarin.Forms; using Xamarin.Forms.Viewer; |
C# |
Copy Code
|
---|---|
Assembly assembly; //Bind FlexViewer control to the PDF assembly = IntrospectionExtensions.GetTypeInfo(typeof(MainPage)).Assembly; Stream stream = assembly.GetManifestResourceStream("App4.Resources.DefaultDocument.pdf"); |
Load the PDF document in the FlexViewer control using the following code. In this example, we have added a PDF document to the Resources folder to load it in the viewer.
C# |
Copy Code
|
---|---|
//Load PDF document to the viewer
flexViewer.LoadDocument(stream);
|
The following code shows the class constructor App() after completing this step.
C# |
Copy Code
|
---|---|
public App() { // The root page of your application MainPage = new QuickStart(); } |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Viewer.Platform.iOS.FlexViewerRenderer.Init(); |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Viewer.Platform.UWP.FlexViewerRenderer.Init(); |
(Optional) In case you compile your UWP application in Release mode, you need to explicitly add the following code to the OnLaunched method in your App.xaml.cs to include the correct assemblies within your application.
C# |
Copy Code
|
---|---|
var assembliesToInclude = new List<Assembly>(); assembliesToInclude.Add(typeof( C1.Xamarin.Forms.Viewer.Platform.UWP.FlexViewerRenderer).GetTypeInfo().Assembly); assembliesToInclude.Add(typeof(C1.UWP.Viewer.FlexViewer).GetTypeInfo().Assembly); Xamarin.Forms.Forms.Init(e, assembliesToInclude); |