Using PdfSharp, a .NET Library for Processing PDF from Native C++

PDFsharp is the Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.

PDFsharp has the following key features,

  • Creates PDF documents on the fly from any .NET language
  • Easy to understand object model to compose documents
  • One source code for drawing on a PDF page as well as in a window or on the printer
  • Modify, merge, and split existing PDF files
  • Images with transparency (color mask, monochrome mask, alpha mask)
  • Newly designed from scratch and written entirely in C#
  • The graphical classes go well with .NET

With xInterop Native C++ to .NET Bridge, we can create a native C++ bridge DLL for the PDFsharp library assembly easily. By creating a native C++ bridge to the PDFsharp library assembly, we got ourselves a very nice and powerful C++ PDF library. And PDFsharp is published under the MIT License. Once you have a paid version of xInterop Native C++ to .NET bridge, you can create Native C++ bridge DLL to as many as .NET library as you want, including PDFsharp library.

C++/CLI can also be used to create C++ bridge/wrapper to PDFsharp library assembly, but it will take too much time to create such a C++ bridge/wrapper to such a library as complicated as PDFsharp library. On top of that, developers will have to learn C++/CLI if they have not already, in my opinion, it is a pain to learn C++/CLI. If you already have C++ knowledge, it costs you nothing to learn xInterop Native C++ to .NET Bridge, it is just as simple as configuration using a few forms/windows.

Let’s start creating an xInterop Native C++ to .NET Bridge project.

Step 1: Create a new xInterop C++ .NET Bridge

image

Step 2: Choose Native C/C++ to .NET Bridge project

image

Step 3: Sets up the targeting .NET assembly and the options.

image

Step 4: Choose the .NET classes to create native C++ bridge classes.

image

Step 5: Start creating the Native C++ Bridge DLL and associated .NET Bridge assembly Visual Studio project.

image

The process of creating a Native C++ Bridge DLL and associated .NET Bridge assembly Visual Studio project is much slower than simply creating a .NET to Native C++ Bridge whose underlying native C++ usually contains less C++ classes. It usually takes between minutes to hours depending on the number of classes contained in the .NET assembly, or the number of .NET classes users pick. But it is the computer who does the job, once set up and configured, users barely need to do anything to the Native C++ Bridge DLL, it is ready for use immediately after it is done.

Step 5:

image

image

Step 6: Open the TestApp Visual Studio Solution

image

When you look at the TestApp.cpp file, you will find that a skeleton application has already been created as the code shows below.

We are also showing you the partial header file of the PDFsharp native C++ bridge DLL.