It is possible to use Aspose.Pdf from within COM applications such as ASP and VBScript projects. This section outlines what you need to know in order to successfully use Aspose.Pdf from within a COM application.
Aspose.Pdf support for COM, is a new feature in its early stages. Aspose.Pdf was not initially designed with COM clients in mind so you might experience some problems during integration. Please report any problem you face in the Support Forums of Aspose.Pdf and we will try to help you asap.
Installation
You should use the official installer, Aspose.Pdf.msi because it registers Aspose.Pdf.dll for COM interoperability automatically.
If you just copy a hotfix Aspose.Pdf.dll, it will not work because COM registration is tied to the dll version. If you still want to apply a hotfix, you need to register it manually by executing this command:
regasm \Aspose.Pdf.dll /codebase |
regasm.exe is a tool included in .NET Framework and must be somewhere in the C:\WINNT\Microsoft.NET folder.
Restrictions
Please note that Aspose.Pdf does not implement COM interfaces explicitly and relies on .NET to automatically expose a dispinterface of the class to COM clients on request. The dispinterface does not exhibit the versioning problems that could arise because of frequent Aspose.Pdf releases because clients can only late bind to the interface. There is no type library provided with the component.
Note: There is no type library provided with the component.
Usage
There are two important points you should keep in mind: Usage of overloaded methods and enumerations.
Some methods have overloads and they are exposed to COM clients with a number suffix added to them except the very first method that stays unchanged. For example, Pdf.Save method overloads become Pdf.Save, Pdf.Save_2, Pdf.Save_3, and so on. The order in which method overloads are shown in the API documentation corresponds to the way they are numbered. This is the approach that .NET COM Interop takes to make overloaded methods available to COM clients.
For enumeration values like AlignmentType.Center, you will need to generate a type library from Aspose.Pdf.dll and open it in some type library viewer to lookup the enumeration values. You can view a type library using Microsoft Visual Basic 6, Visual Basic for Applications in Microsoft Word or OLE Viewer. To generate a type library, use another .NET Framework SDK tool, tlbexp as shown below:
tlbexp Aspose.Pdf.dll |
Code Snippet
[VBScript]
<html>
<head>
<title>Aspose.Pdf ASP sample</title>
</head>
<body>
<h3>Aspose.Pdf ASP sample</h3>
<%
'Create a Pdf document
Dim Pdf1
Set Pdf1 = CreateObject("Aspose.Pdf.Pdf")
'Set license for Aspose.Pdf
Dim lic
Set lic = CreateObject("Aspose.Pdf.License")
lic.SetLicense ("D:\CSharp\customer\Aspose.Pdf.lic")
'Create a section object
Dim sec1
set sec1 = server.CreateObject("Aspose.Pdf.Section")
'Add section to the Pdf document
pdf1.Sections.Add(sec1)
'Create a text paragraph
Dim t1
set t1 = server.CreateObject("Aspose.Pdf.Text")
'Create a text segment
Dim s1
set s1 = server.CreateObject("Aspose.Pdf.Segment")
'Add content to the text segment
s1.Content = "hello"
'Add the segment to the text paragraph
t1.Segments.Add(s1)
'Add text paragraph to the section of the Pdf document
sec1.Paragraphs.Add(t1)
'Save the Pdf document
pdf1.Save "D:/share/test.pdf"
%>
</body>
</html>