Recently I have been working on an PDF Viewer. Basically a desktop application that has the ability to launch a PDF file. Previously the application relied on integration with Adobe and a hefty license fee.
So an open source PDF viewer was required. Step up pdf.js. This project is fantastic. It's regularly updated and has great support. The fact that its created by Mozilla developers is also reassuring.

PDF.js - How It Works

PDF.js is a HTML 5 project and powered by javascript that basically takes a PDF document and copies the content into a HTML layer that is set on top of the PDF. This is quite clever as this now allows functionality like text selection to be enabled because you are basically selecting a div on top of the PDF. The project comes with a viewer.aspx file where this HTML layer is dynamically added. You can see it in action. To get it running you just drop the files into your project and add the references to the javascript file into your viewer HTML page. There are plenty of examples out there to get a basic viewer up and running.

PDF.js is an online PDF viewer, designed for viewing PDFs on the web. My requirement was to create an offline viewer. So at this point I had a HTML page which could render PDFs online. To make this work offline for a desktop application I needed the ability to render HTML in a browser control. A free browser control. Step up open source project number 2.

Chromium Embedded Framework

CEF. Or Chromium Embedded Framework. This is a web browser control based on the Google Chromium project. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and WebKit implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser. Now I'm not a C or C++ developer, so I used a project called cefglue, which is a .NET wrapper for CEF. CEF allows you to pass in a URL and loads it into the chromium browser control.

So I converted my viewer.aspx into a HTML page. I then pass this page into the cef browser, which then renders it and runs the pdf.js javascript. Voila! My PDF is now displayed in a control that can run offline.

At some point I will create a post with some code which will maybe make this post understandable.