How Do I Programmatically Create a PdfView?
To programmatically create a PdfView
:
-
Initialize the SDK.
-
Create a
PdfView
object in theOnNavigatedTo
handler of thePage
. -
Add a handler for
PdfView.InitializationCompletedHandler
. -
Add the
PdfView
to the children of a UI element on thePage
.
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>