Using PdfSharp for Processing PDF from Native C++ : Watermark Sample

The whole package of PdfSharp comes with lots of sample applications, one of them is watermark sample which shows three variations how to add a watermark to an existing PDF file.

You can see the resulting PDF as shown below.

image

image

image

The following is the original C# console application of Watermark sample. The C# source code was released under MIT and it was written by Thomas Hövel.

In the previous article, we talked about how to use xInterop C++ .NET Bridge with Native C++ to .NET Bridge to generate the native C++ bridge DLL for PDFsharp .NET library assembly. In this Watermark example, we will need to use the native C++ bridge DLL PdbSharpgidBridge.DLL.

The following is the complete source code of the example.

The C++ code is very similar to the C# counterpart since we can simulate the C# property in the C++ code. The native C++ application creates exactly same PDF file as the one generated by the C# console sample application. Let’s go over the important steps before we can start calling the functions.

1. Include the header file for the native C++ Bridge DLL.

image

2. Reference the native C++ Bridge lib files.

image

3. Define all the required namespace inclusion.

image

See the difference between .NET namespace and Native C++ namespace

image

There are a few things worth mentioning in the C++ code.

1. Open an existing document.

image

2. Using properties.

image

In the preceding screen-shot, Version is a property. We are using them just like using the properties in the C# code.

3. System.Diagnostics.Process class

image

We also created the native C++ bridge class for the .NET class of Process, the screen-shot above shows how to use them.

Translate »