.net PDFViewer Component

Today I wanted to Integrate a PDFViewer component into my own .net (C++/CLI) application. In the beginning I hoped to find an opensource component for this. There are several opensource library’s for creating PDF’s with .net but none of them provided a PDFViewer component. There are several commercial solutions available but since they usually provided much more than I needed I was not really interested. On Linux or with other GUI toolkits (GTK, QT4 or Java) there are opensource alternatives available for the viewer but not for .net.

After a while I found a description that it is possible to integrate the Adobe Reader via ActiveX. Armin sent me a short C# example how to do it. Sadly I could not find the necessary dll’s. After some search for this dll’s I found the documentation page of Adobe where they provide examples for the usage of the Adobe Reader within a C# application. After compiling this application I found the needed dll’s in the output directories of this project and then I could set up my application just fine.

The only problem with the examples where that they where unnecessary complicated. I reduced the example to a minimum needed and created a small example application. The example including a short description can be found in the enterpriselab wiki:

Some more interesting links I found during my research:

Managed C++ vs. C++/CLI vs. C++

When I started my latest project where I needed some basic C libraries to access the Hardware. I thought I will use a Windows Forms Application with C++. I hoped this offers me writing normal C++ code and still use the new UI code from MS. In addition it would possible to port the application since the underlying C library is platform independent and C++ if correctly separated from the UI code should compile as well.

To bad it was not as easy as I hoped it will. The next time I might just chose an MFC Application where I can write native C++ code and I don’t have to bother with some magic C++ addition.

I had quite a hard time to figure out how I need to structure my application that it will work in managed mode. After some googeling I figured out that there are two different things: Managed C++ and C++/CLI. Managed C++ was the old addition from MS. With Visual Studio 2005 they added C++/CLI which is an ECMA standard and has a similar scope as Managed C++. The keywords of C++/CLI are no more marked with two underlines in front as it was with Managed C++. At the end I found an overview that explained me the strange keywords that I found in the new generated code.

The following links give a good overview about the differences between the C++ and C++/CLI:

The result of all this is that my application will not be portable at all since all the code is infected with CLI code. It would have been possible to separate the C++ code from the CLI code in such a way that it could be reused on an other platform but since it is only a prototype and it just has to work on windows. I will leave that for an other time. To separate C++ code from C++/CLI code it is necessary to write some glue code since CLI does not support all features from C++.