Integrating PSPDFKit Manually

To include PSPDFKit in your app, install the PSPDFKit for Windows.vsix Visual Studio Extension — installation steps are outlined below. Learn more about PSPDFKit for Windows in our announcement blog post and on our SDK product page.

Requirements

  • Windows 10
  • Visual Studio 2017
  • UWP-based application x64 or x86
  • PSPDFKit for Windows.vsix Visual Studio Extension

If you encounter any problems during the integration, please let us know.

Basic Integration

After making sure Visual Studio is closed, double-click on the installer, PSPDFKit for Windows.vsix.

Open Visual Studio and create a new blank UWP app in, for example, C#, with the project wizard.

New app project

Open package.appxmanifest, which you will see near the bottom of your Solution Explorer.

The rightmost tab, Packaging, has a field called Package name.

It is essential that your package name matches the bundle ID of your license.

Package name

Right click on References in the Solution Explorer and then select Add Reference.

Navigate to Universal Windows > Extensions, and then select PSPDFKit for UWP and Visual C++ 2015 Runtime for Universal Windows Platform Apps.

Click on OK and you should see the following in your references.

References

In the Solution Explorer, open the file App.xaml.

Add your license key as a String value in the application’s resources:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <x:String x:Key="PSPDFKitLicense">YOUR_LICENSE_KEY_GOES_HERE</x:String>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

</Application>

Open the main page XAML and paste the following XML as a child of the <Grid> element:

Copy
1
2
3
4
5
6
<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="52"/>
</Grid.RowDefinitions>
<ui:PdfView Grid.Row="0" Name="PdfView" License="{StaticResource PSPDFKitLicense}" />
<Button Content="Open PDF" HorizontalAlignment="Left" Margin="10" Grid.Row="1" Name="Button_OpenPDF" Click="Button_OpenPDF_Click"/>

You’ll see a green line under ui:PdfView. If you hover over it, you will be given the option for potential fixes. Click on this, and Visual Studio will suggest that you include the missing namespace, which you should do. It will then add the following namespace to <Page>:

1
2
3
<Page
    xmlns:ui="using:PSPDFKit.UI"
/>

Open the MainPage.xaml.cs file and add this function to the MainPage class:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private async void Button_OpenPDF_Click(object sender, RoutedEventArgs e)
{
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
    picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
    picker.FileTypeFilter.Add(".pdf");

    var file = await picker.PickSingleFileAsync();
    if (file != null)
    {
      var document = DocumentSource.CreateFromStorageFile(file);
      await PdfView.Controller.ShowDocumentAsync(document);
    }
}

In the Build toolbar, choose Debug and x86 or x64 — whichever you prefer.

Then in the menu, select Build > Build Solution.

The solution should build without complaint.

Start the application, and you should be able to open a PDF by clicking on the Open button.

Catalog App

Catalog

The Catalog app contains a lot of useful examples for exploring the different features of PSPDFKit and getting started quickly. You can find the example Catalog sources inside the customer portal or by requesting an evaluation license of PSPDFKit.

React Native for Windows UWP Support

PSPDFKit for Windows UWP comes with optional support for React Native. This makes it very easy to add PDF support to your React Native Windows app. See our open source GitHub repository for details on how to integrate.