> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/uwp/get-started/viewdoc.md).

# Viewing a document in your UWP application

Learn how to integrate a PDF viewer into your Windows app with step-by-step instructions. Update xaml, add the viewer, and enhance functionality easily. The Apryse uwp SDK streamlines secure document

## Prerequisites

Please refer to either [Download and integrate manually](/uwp/get-started/integration/pdfnetcuwp.md) or [Integrate with NuGet guide](/uwp/get-started/integration.md).

## Step 1: Update xaml

Now that the project is set up, let us add a PDFViewCtrl as the main feature of the project. First, we need to set up the page to contain the PDFViewCtrl. We want to add a main viewing area for the PDFViewCtrl, and an area at the bottom where we can later add in some options. Open up “MainPage.xaml” and find the Grid element. Add some row definitions as follows:

{% tabs %}
{% tab title="XAML" %}
{% code lineNumbers="true" %}

```xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>
</Grid>
```

{% endcode %}
{% endtab %}
{% endtabs %}

The second row will be used for our options bar, while the first row will use whatever space is left to display the PDFViewCtrl.

To this Grid, let's add a Border which will host the PDFViewCtrl and then a stack panel with a button to open a document.

{% tabs %}
{% tab title="XAML" %}
{% code lineNumbers="true" %}

```xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>

  <Border x:Name="PDFViewBorder" Grid.Row="0"/>

  <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
    <Button x:Name="OpenButton">Open</Button>
  </StackPanel>
</Grid>
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Step 2: Add the viewer

Now, we want to add the PDFViewCtrl to the app. We do this in “MainPage.xaml.cs”. Open up “MainPage.xaml.cs” and add a member variable that references a PDFViewCtrl.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
public sealed partial class MainPage : Page
{
    pdftron.PDF.PDFViewCtrl MyPDFViewCtrl;
    ...
```

{% endcode %}
{% endtab %}
{% endtabs %}

Next, we need to initialize PDFNet and create a PDFViewCtrl, so let's do this in the constructor of the MainPage. We also need to make the PDFViewCtrl the child of the PDFViewBorder.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
public MainPage()
{
    this.InitializeComponent();
    pdftron.PDFNet.Initialize("your_key");
    MyPDFViewCtrl = new pdftron.PDF.PDFViewCtrl();
    PDFViewBorder.Child = MyPDFViewCtrl;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

We also have to add a handler for the Open button. Let's do that in MainPage's constructor after we have created a PDFViewCtrl.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
public MainPage()
{
    this.InitializeComponent();
    pdftron.PDFNet.Initialize("your_key");
    MyPDFViewCtrl = new pdftron.PDF.PDFViewCtrl();
    PDFViewBorder.Child = MyPDFViewCtrl;
    OpenButton.Click += OpenButton_Click;
}

void OpenButton_Click(object sender, RoutedEventArgs e)
{
    throw new NotImplementedException();
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Inside this click function, we need to open a Document. First, let's include two new namespaces that we need for the file picker and for the storage file.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
using Windows.Storage;
using Windows.Storage.Pickers;
```

{% endcode %}
{% endtab %}
{% endtabs %}

Also, OpenButton\_Click needs to be async in order to handle some of the asynchronous API's needed here. So, replace the old OpenButton\_Click with the following:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
async void OpenButton_Click(object sender, RoutedEventArgs e)
{  
    // Get a file from the file picker.
    FileOpenPicker fileOpenPicker = new FileOpenPicker();
    fileOpenPicker.ViewMode = PickerViewMode.List;
    fileOpenPicker.FileTypeFilter.Add(".pdf");
    StorageFile file = await fileOpenPicker.PickSingleFileAsync();

    // Create a PDFDocument and use it as the source for the PDFViewCtrl
    if (file != null)
    {
        Windows.Storage.Streams.IRandomAccessStream stream = await
            file.OpenAsync(FileAccessMode.ReadWrite);
        pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc(stream);
        MyPDFViewCtrl.SetDoc(doc);   
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Build and launch the app and we should now have a very basic PDF document viewer.

Do note that in Windows 8.1, the file picker works differently. Please see this guide for how to use file pickers in Windows Phone 8.1: <https://msdn.microsoft.com/en-us/library/windows/apps/dn642086(v=vs.105).aspx>

## Step 3: Adding Text Selection, Form Filling, and More

The basic viewer doesn't support text selection, for example, out of the box. For this, we will need the tools package from NuGet or the tools project contained in the download package.

{% tabs %}
{% tab title="NuGet" %}
If you integrated PDFTron.UWP using NuGet then use the tools package `PDFTron.UWP.Tools` in the package manager.

Find your project in the Solution Explorer. Right Click on the project and click on `Manage NuGet Packages...`. In the package manager, select the **Browse** tab and search for `PDFTron.UWP.Tools`. Install this package.
{% endtab %}

{% tab title="Manually" %}
If you integrated manually with the Apryse UWP download package then use the tools package in the samples folder from the download.

1. First, we will add a new reference to the tools library. The tools library is shipped as part of the samples that come with the SDK. We can include the tools project in this solution.In the solution explorer, right click on the PDFNetSample solution and select `Add` -> `Existing Project...`. Navigate to the folder where the PDFNet package was unzipped, Open the Lib Folder, Framework Folder and then the Tools\_VS2019 Folder. Inside here you should find Tools\_VS2019.csproj. Select it and select Open.
2. Since the Tool\_VS2019 projects references the PDFTron.UWP NuGet package we will need to remove it in order to use the VSIX / Extension Apryse's UWP SDK. To do so right click the Tools\_VS2019 project in the solutions explorer, click `Manage NuGet Packages` then select `PDFTron.UWP` -> `Uninstall`.
3. Now, we want to add the Tools\_VS2019 project as a reference used by PDFNetSample. We can do this in a similar way to how we added PDFNet for Windows Universal Apps. In the solution explorer, in the PDFNetSample solution, right click on References and select `Add Reference...` In the dialog, select `Project` -> `Solution` and find Tools\_VS2019 in the list. Select it and add it by clicking OK.
4. Right click on References in the Tools\_VS2019 project in the solution explorer and select `Add Reference...`. In the left pane of the dialog, select `Universal Windows`. Then select `Extensions` and in the list that appears, check the box next to `PDFNet SDK for UWP`.
5. Now that we have the Tools library referenced in your UWP application, we need to create a ToolManager and attach the PDFViewCtrl to it. Declare another member variable in MainPage.xaml.cs next to MyPDFViewCtrl.
   {% endtab %}
   {% endtabs %}

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
pdftron.PDF.PDFViewCtrl MyPDFViewCtrl;
pdftron.PDF.Tools.ToolManager MyToolManager;
```

{% endcode %}
{% endtab %}
{% endtabs %}

Inside the constructor for MainPage we now add one more call where we initialize the ToolManager.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
public MainPage()
{ 
    this.InitializeComponent();
    pdftron.PDFNet.Initialize("your_key");
    MyPDFViewCtrl = new pdftron.PDF.PDFViewCtrl();
    PDFViewBorder.Child = MyPDFViewCtrl;
    MyToolManager = new pdftron.PDF.Tools.ToolManager(MyPDFViewCtrl);
    OpenButton.Click += OpenButton_Click;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

This is all you need for text selection to work. The tools support many other operations, such as creating and adding basic shapes to the PDF document and editing form fields.

## Next step

<a href="/uwp/get-started/customize.md" class="button primary">Customize</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/uwp/get-started/viewdoc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
