Microsoft Xamarin

PSPDFKit for Windows UWP includes full-featured bindings for Xamarin. We work closely with Xamarin to provide up-to-date bindings shortly after our regular PSPDFKit releases.

Using PSPDFKit for Windows in Your Xamarin.Forms UWP Project

To use PSPDFKit for Windows in your Xamarin.Forms UWP project, you first need to follow the PSPDFKit for Windows integration guide. Then you can create a Xamarin.Forms control that inherits from Xamarin.Forms.View. This can be used to host the actual PdfView using a Xamarin.Forms custom renderer technique. We encourage you to read the Xamarin.Forms documentation — specifically the Implementing a View article — as we use this pattern in our example project.

Xamarin.Forms Custom Control

  • PdfViewer.cs: This is the Xamarin.Forms custom control that is used to represent a PdfView in the Xamarin.Forms context. In this particular example, it mirrors properties that are bindable from a XAML context.
  • PdfViewerRenderer.cs: This is the class that will actually contain the PdfView object initialization and implementation. PdfViewerRenderer.cs is hosted in the UWP project context, so it has access to all UWP platform features. The Creating the Custom Renderer on UWP document goes into greater detail on this subject.

Now that you have both pieces in place, you can use PdfViewer.cs from the Xamarin.Forms XAML context like this:

Copy
1
2
3
4
5
<ContentPage.Content>
	<PdfViewer
		License="{StaticResource PSPDFKitLicense}"
		PdfUriSource="ms-appx:///Assets/pdfs/default.pdf"/>
</ContentPage.Content>

ℹ️ Note: PdfViewer.cs and PdfViewerRenderer.cs are just provided as a way to render a PDF within a Xamarin.Forms UWP application. You can achieve the same result by creating a UWP page to host the PdfView and your own UWP logic and by using a Xamarin.Forms.ContentPage as a container of said UWP page. This is also demonstrated in the PrintPageContainer.cs, PrintPageRenderer.cs, PrintPage.xaml.cs, and PrintPage.xaml samples.

Example Project

We have a great example project called XamarinPDF. It shows how to build an app with PSPDFKit for Windows UWP using Xamarin.Forms. To run this example, simply follow the steps provided in the Xamarin-UWP repo README.