Skip to content

Load a PDF in Windows Store App (8.1 & UWP)

I’m working on a project where users are going to load a PDF, but will be returning to the same PDF again and again. I was having some problems with Microsoft’s normally amazing PDF showcase application on lower end devices (my app needs to run well on an original Surface), so I tested this solution out.

So far it’s working really well. The navigation is clean and fast, loading times are great, even for PDFs that are upwards of 100 pages.

The downsides are

  1. the initial “processing” time (splitting the pages up and saving them as images) is a little costly. For my larger PDFs, it can take 90-120 seconds on a Surface 1. But once the PDF is split into individual images, loading is very fast.
  2. I’m missing things like page zooming, semantic zoom. If that is something that matters, check out the showcase application above.

Full source here at my github.

First, I added a FlipView to my XAML. The ItemTemplate is basically just an image.

XAML

The file I’m loading is loaded locally in my application. But you could download the PDF to a StorageFile and load it from there using this same code. Then use PdfDocument to load the file.

CSharpOne

Then I just run through the PDF document page by page and render them out to image files.

CSharpTwo

At the bottom of this snippet, I add the image path to PdfImages, an ObservableCollection<string> object. Then I just bind my FlipView to that collection.

CSharp3

For this sample, I included a 36 page full-color PDF. It loads the PDF and renders and saves the PDF files in about a second.

sample