Aspose.PDF for .NET via COM Interop

Working with COM Interop

Aspose.PDF for .NET executes under the control of the .NET Framework and this is called managed code. Code written in all of the above languages runs outside the .NET Framework and it is called unmanaged code. Interaction between unmanaged code and Aspose.PDF occurs via the .NET facility called COM Interop.

Aspose.PDF objects are .NET objects, but when used via COM Interop, they appear as COM objects in your programming language. Therefore, it is best to make sure you know how to create and use COM objects in your programming language, before you start using Aspose.PDF for .NET.

Here are the topics that you will eventually need to master:

Register Aspose.PDF for .NET with COM Interop

You need to install Aspose.PDF for .NET and make sure it is registered with COM Interop (ensuring that it can be called from unmanaged code).

Pay attention that /codebase is necessary only if Aspose.PDF.dll is not in GAC, using this option makes regasm put path for assembly in registry.

ProgIDs

ProgID stands for “programmatic identifier”. It is the name of a COM class that used to create an object. ProgIDs consist of the library name “Aspose.PDF” and the class name.

Type Library

Creating COM Objects

The creation of a COM object is similar to creation of a normal .NET object:

'Instantiate Pdf instance by calling its empty constructor

Dim pdf
Set pdf = CreateObject("Aspose.Pdf.Generator.Pdf")

Once created, you are able to access the object’s methods and properties, as if it was a COM object:

'Add section to Pdf object
pdf.Sections.Add(pdfsection)

Some methods have overloads and they will be exposed by COM Interop with a numeric suffix added to them, except for the very first method that stays unchanged. For example, the Pdf.Save method overloads become Pdf.Save, Pdf.Save_2, and so on.

For more information, see the language-specific articles further in this documentation.

Creating a Wrapper Assembly

If you need to use many of Aspose.PDF for .NET classes, methods and properties, consider creating a wrapper assembly (using C# or any other .NET programming language). Wrapper assemblies help help to avoid using Aspose.PDF for .NET directly from unmanaged code.

A good approach is to develop a .NET assembly that references Aspose.PDF for .NET and does all the work with it, and only exposes a minimal set of classes and methods to unmanaged code. Your application then should work just with your wrapper library.

Reducing the number of classes and methods that you need to invoke via COM Interop simplifies the project. Using .NET classes via COM Interop often requires advanced skills.