How do I programmatically create a PdfView?

To programmatically create a PdfView:

  1. Initialize the SDK.
  2. Create a PdfView object in the OnNavigatedTo handler of the Page.
  3. Add a handler for PdfView.InitializationCompletedHandler.
  4. Add the PdfView to the children of a UI element on the Page.

Once initialization is complete, you can display a PDF:

namespace App1
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
PSPDFKit.Sdk.Initialize("YOUR_LICENSE_GOES_HERE");
}
private PdfView _pdfView;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_pdfView = new PdfView();
_pdfView.InitializationCompletedHandler += PdfView_InitializationCompletedHandler;
Grid.Children.Add(_pdfView);
}
private async void PdfView_InitializationCompletedHandler(PdfView sender, PSPDFKit.Pdf.Document args)
{
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/A.pdf"));
_pdfView.PdfFileSource = storageFile;
}
}
}
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Name="Grid">
</Grid>
</Page>