> 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/viewer/using-pdfviewctrl.md).

# Display a PDF in PDFViewCtrl for your UWP viewer

Learn how to display a PDF file in PDFViewCtrl with this step-by-step tutorial. Set up your project, add PDFViewCtrl, and create a basic PDF document viewer in UWP. The Apryse uwp SDK streamlines secu

In this tutorial you will be able to display a PDF file in [`PDFViewCtrl`](https://sdk.apryse.com/api/uwp/guides/html/8d6e5545-146a-ff14-0590-365981bc8abe.htm). To begin working with `PDFViewCtrl`, you must have first added it to your project and initialized the library ([get started with UWP](/uwp/get-started/integration.md)).

1. 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: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="XML" %}
{% code lineNumbers="true" %}

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

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

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

```xml
<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 %}

1. 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`.Next, we need to 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 sealed partial class MainPage : Page
 {
     pdftron.PDF.PDFViewCtrl MyPDFViewCtrl;
     ...
 }
```

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

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

```csharp
public MainPage()
  {
      ...
      MyPDFViewCtrl = new pdftron.PDF.PDFViewCtrl();
      PDFViewBorder.Child = MyPDFViewCtrl;
  }
```

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

1. 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`.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.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
public MainPage()
  {
      ...
      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 %}

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

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

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

{% 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>


---

# 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/viewer/using-pdfviewctrl.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.
