Implement PDF Viewer Control in UWP app

This guide goes over the steps to implement the Viewer Control in a UWP application

  1. To begin working with ViewerControl, you must have first initialize the Apryse's UWP SDK by calling pdftron.PDFNet.Initialize("your_key") at the initialization of your application.
  2. Add WinUI 2 resources to the applicationWhen using WinUI library it is necessary to call it's resource dictionary and add it to the application's resources otherwise the application might crash with a missing resource (style or theme) not found issue

XML

1<Application.Resources>
2 <ResourceDictionary>
3 <ResourceDictionary.MergedDictionaries>
4 <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
5 </ResourceDictionary.MergedDictionaries>
6 </ResourceDictionary>
7 </Application.Resources>

For more information on starting with WinUI please follow the official Microsoft getting started guide

  1. Enable Share Document Feature by adding runtime directivesIn order to use the Share feature, it is necessary to add System.Collections.Generic.List{} directive to the Default.rd file

XML

1<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
2 <Application>
3 <!-- An Assembly element with Name="*Application*" applies to all assemblies in the application package. The asterisks are not wildcards. -->
4 <Assembly Name="*Application*" Dynamic="Required All" />
5
6
7 <!-- Add your application specific runtime directives here. -->
8 <Type Name="System.Collections.Generic.List{}" MarshalObject="Required All"/>
9
10 </Application>
11 </Directives>
  1. Enable support for MS Office Conversion by adding the required resource files to the project. To do this go into the solution explorer, right click your solution, and click Add -> Existing Item.... Go to the UWP SDK folder -> Resources and add the files pdftron_exotic_font_resources.plugin, pdftron_layout_resources_.plugin, and pdftron_smart_substitution.plugin. For each file, right click the file and click properties and change the Build Action to Content.More information on MS Office Conversion guides.
  2. Add ViewerControl to a pageViewerControl can be easily added to a UWP App page.

XML

1<Page x:Class="MyUWPApp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewer="using:pdftron.PDF.Tools.Controls.Viewer" mc:Ignorable="d">
2
3 <viewer:ViewerControl/>
4 </Page>
  1. Check the ViewerControl sample appYou can also check a sample project that implements the ViewerControl

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales