Share via


PDF Viewing Components for Windows Store apps (WinRT) (XAML/C#)

Updated 4/7/2014 to reflect Windows 8.1 PDF API capabilities and new SDK samples

Microsoft released a componentized, high-performing PDF viewing component for XAML/C# applications on 4/2/2014. Woohoo! This serves as a good reference sample of how this needs to be done (C# front-end with a C++ back-end).

If you want more bells and whistles, a number of third parties add more to the reader experience such as alternate viewing methods (facing page vs. continuous view, etc). Figure 1 shows a breakdown of all the components that I have seen. These are all expensive (from $495 to “if you have to ask, it’s too expensive”), so they might not work well for a hobbyist app developer. But if you have a need in your commercial or LOB application, you may find one of these to be useful. 

Vendor / Sample App Rendering Annotations Full Text Search License
PDFTron Mobile PDF SDK / Drawboard Proprietary Yes Yes $$$$
Foxit Embedded PDF SDK for Windows RT / Foxit Mobile PDF Proprietary Yes Yes $$$$
PDF Xpansion SDK / Perfect PDF Proprietary Yes Yes $$$$
DevExpress Windows 8 XAML Controls / Army Field Manuals Microsoft No No $$
ComponentOne XAML Controls / ComponentOne XAML Controls Microsoft* No No $$
Syncfusion Essential Studio for WinRT/XAML Proprietary No No $$
Windows.Data.PDF Microsoft No No MS-LPL
PdfShowcase Example Microsoft No No MS-LPL
MuPDF WinRT / PDF Touch Proprietary Yes No? GPL / $$$$
Offline Rasterization w/Ghostscript Proprietary No No GPL / $$$$
Any .NET Brokered Component** Proprietary Not Sure Not Sure Varied

Fig 1. PDF Viewing Components for Windows Store applications

* Offers two rendering modes – one that converts to XAML and another that uses the PDF API
** Windows 8.1 Update offers the ability for enterprise apps to broker desktop components for use in WinRT applications.

If you know of others, please post a reply or send me a tweet @paulwhit. I’m actively monitoring this topic.

Also Ahmed-Faoud has ported MuPDF for use in Windows Store applications. This is very fast, but carries a GPL license.

If high performance viewing of large or complex documents isn’t a consideration for your use case, you could provide rasterization to bitmap images either within your application at runtime or on a load event or background task, or by using a batch process like below. You could then load them in a ListView control and you should get pretty good performance. Rasterizing the PDF pages on the fly in a ListView is probably going to be too slow, especially on a low-powered device.

As an example, I’m using some C# code in a batch application to generate thumbnails for my Army Field Manuals app. I’m distributing the images with my app, so there’s no processor use on the client.

To rasterize the first page of a PDF document as a thumbnail, in a Windows Store application, add this to a button click event handler. The “file” variable is a file path. A quick way to access a local file is to put it in your %localappdata%\packages\{app id}\LocalState path and use ApplicationData.Current.LocalFolder to retrieve its file name.

var pdfDoc = await PdfDocument.LoadFromFileAsync(file);
var pdfPage = pdfDoc.GetPage(0);

var pageImageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"sm_" + Path.GetFileNameWithoutExtension(file.Path) + ".scale-100.png", CreationCollisionOption.ReplaceExisting);
var randomStream = await pageImageFile.OpenAsync(FileAccessMode.ReadWrite);
PdfPageRenderOptions options = new PdfPageRenderOptions();
options.DestinationWidth = 250;
await pdfPage.RenderToStreamAsync(randomStream, options);
await randomStream.FlushAsync();

randomStream.Dispose();
pdfPage.Dispose();

There is a team dedicated to the PDF APIs at Microsoft. You can find the PDF API team’s blog led by program manager Shalu Gupta on TechNet.

For the record, I am currently using DevExpress in my Army Field Manuals app.

Comments

  • Anonymous
    April 03, 2013
    Amyuni PDF Creator for WinRT is currently available as pre-release trial. This a commercial library that allows rendering and editing PDF files in WinRT apps. It can be used for rendering as a Xaml control in Xaml-based projects or as a PDF-to-HTML5 converter in WinRT-Javascript projects. Features details can be found here: www.amyuni.com/.../Developer_Documentation.htm The library can be downloaded from here: www.amyuni.com/.../trialdownloads

  • Anonymous
    July 19, 2013
    PDF Rendering in Store apps has become really easy with Windows 8.1. Windows 8.1 now has PDF rendering APIs and ability to save/show PDF pages as images. Check out samples @ code.msdn.microsoft.com/.../PDF-viewer-sample-85a4bb30

  • Anonymous
    November 09, 2013
    All of these 3rd party libraries are highway robbery.  Thank you Microsoft for giving its developers the power to render PDFs without the huge expense of a third party control.  I just wish it was in Windows 8.0

  • Anonymous
    April 28, 2014
    Is there a similar Android solution for opening PDF files INSIDE an app? Thanks for these links... I'd like one SDK that supports both Windows and Android but I doubt I'll get that. Oh well.

  • Anonymous
    April 28, 2014
    I'm looking for an SDK or similar that will allow me to open PDF files INSIDE my app. I need this on both Win RT (ARM and x64/x86) and Windows Phone.

  • Anonymous
    June 09, 2014
    Dear Ryan, PDF Xpansion SDK 10 meets the requirements you mentioned in your second post. A trial version including sample code is available via the link "PDF Xpansion SDK". If you have questions, please do not hesitate to ask, PDF@soft-xpansion.com. Regards Frank

  • Anonymous
    January 08, 2015
    Is this page up to date? Are there any new players on the market?

  • Anonymous
    July 28, 2015
    Our XFINIUM.PDF library supports PDF rendering for Windows 8.1 and Windows 10 Universal Applications: xfiniumpdf.com/.../xfinium-pdf-overview.html

  • Anonymous
    August 08, 2015
    Is there a way to generate a new pdf document from a bimap image? I am using the Bitmap encoder in my app to save an image of a FrameworkElement and I want to convert that to a pdf.