easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

Using the easyPDF COM Objects

All of BCL's COM Objects can be accessed from a variety of programming environments. This section shows the basics of COM Objects and how to access them.

Note that COM objects are not the only way to use easyPDF. We offer a new API called the Native API, which is available for C, C++, C#, VB.NET, PHP 5+ and Python 3. The native API is more modern and in many ways superior to the classic COM objects.

In this section we are going to discuss how to use the COM API.

COM Objects in Visual C# and Visual Basic .NET

This example shows how to access a COM Object from Visual C# and Visual Basic .NET.

  1. Create a new project. Click Project -> Add References, and select the easyPDF SDK COM Object(s):

  2. Create and use the object.

    Visual C# Code:
    using BCL.easyPDF8.Interop.easyPDFPrinter;

    // ...

    Printer oPrinter = null;
    PrintJob oPrintJob = null;

        oPrinter = new Printer();

        oPrintJob = oPrinter.PrintJob;
        oPrintJob.PrintOut(inFileName, outFileName);
    catch(System.Runtime.InteropServices.COMException err)
        // ...

  3. Visual Basic .NET Code:
    Imports BCL.easyPDF8.Interop.easyPDFPrinter

    ' ...

    Dim oPrinter As Printer = Nothing
    Dim oPrintJob As PrintJob = Nothing

        oPrinter = New Printer()

        oPrintJob = oPrinter.PrintJob
        oPrintJob.PrintOut(inFileName, outFileName)
    Catch ex As System.Runtime.InteropServices.COMException
        ' ...
    End Try

COM Objects in Visual Basic

This example shows how to access a COM Object from Visual Basic.

  1. Create a new project. Click Project -> References, and select the easyPDF SDK COM Object(s):

  2. Create and use the object in VB Code:
    Sub Convert(inFileName As String, outFileName As String)

        Dim oPrinter As easyPDFPrinter.Printer
        Dim oPrintJob as easyPDFPrinter.PrintJob

        On Error GoTo Convert_Error

        Set oPrinter = CreateObject("easyPDF.Printer.8")

        Set oPrinjob = oPrinter.PrintJob
        Call oPrintJob.PrintOut(inFileName, outFileName)

        Exit Sub


        ' ...

    End Sub

COM Objects in Visual C++

This example shows how to access a COM Object from Visual C++.

  1. Create a new Visual C++ project.
  2. Import the BCL COM object:
    #import "C:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepprint.dll"  
  3. Initialize COM library for use by current apartment:
    HRESULT hr = CoInitialize(NULL);
        // failed.
        // ...

  4. Create and Use the object:
    easyPDFPrinter::IPrinterPtr pPrinter = NULL;
    easyPDFPrinter::IPrintJobPtr pPrintJob = NULL;


        pPrintJob = pPrinter->GetPrintJob();
        pPrintJob->PrintOut(lpInFileName, lpOutFileName);
    catch(_com_error &e)
        // ...

  5. Close COM library on the current apartment:
    // Make sure to free all COM objects before calling
    // CoUninitialize(), or you'll get an exception.

    pPrinter = NULL;
    pPrintJob = NULL;


COM Objects in Windows Scripting Host

This example shows how to access a COM Object from Windows Scripting Host.

  1. Create a new Windows Scriptiong Host file (extension ".wsf").
  2. Create and use the object:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

    <job id="demo">
    <?job error="true" debug="true" ?>

    <object id="PrinterSDK" progid="easyPDF.Printer.8" reference="true" />

    <script language="VBScript">

        Set oPrinter = CreateObject("easyPDF.Printer.8")

        Set oPrinjob = oPrinter.PrintJob
        Call oPrintJob.PrintOut(inFileName, outFileName)



Building Your Own .NET COM Interop

In order to use COM objects from .NET, you are required to have a set of .NET COM Interop DLLs. easyPDF SDK comes with the .NET 4 version of these DLLs. If you need to target a different .NET version, you can create your own Interop DLLs in a few minutes.

You are going to need Visual Studio or the .NET SDK. First, you need to open a console by starting cmd.exe, then execute vcvars32.bat. The exact location for this BAT file depends on the version of your Visual Studio:

Visual Studio Version vcvars32.bat location
Visual Studio 2005 "c:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"
Visual Studio 2008 "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
Visual Studio 2010 "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
Visual Studio 2012 "c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat"
Visual Studio 2013 "c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
Visual Studio 2015 "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"

Executing vcvars32.bat ensures that you can call Visual Studio and .NET SDK commands from the command-line.

Now you should change to a working directory using the cd command. This is the directory where all your output files will be generated.

Now you need to create a strong signing key, so that you can digitally sign your own DLLs. You only need to do this once, as the same key can be used again and again. The command for this is the following:

sn -k MyCompany.snk

Now you should have an snk file in your current directory, containing a pair of private and public keys. Should you lose this file, you can always generate a new one from scratch.

Every time you install a new version of easyPDF SDK, you need to regenerate your Interop DLLs using the following 5 commands:

tlbimp "c:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepprint.dll" /primary /keyfile:MyCompany.snk /namespace:BCL.easyPDF8.Interop.EasyPDFPrinter /out:BCL.easyPDF8.Interop.EasyPDFPrinter.dll
tlbimp "c:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepproc.dll" /primary /keyfile:MyCompany.snk /namespace:BCL.easyPDF8.Interop.EasyPDFProcessor /out:BCL.easyPDF8.Interop.EasyPDFProcessor.dll
tlbimp "c:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepconv.dll" /primary /keyfile:MyCompany.snk /namespace:BCL.easyPDF8.Interop.EasyPDFConverter /out:BCL.easyPDF8.Interop.EasyPDFConverter.dll
tlbimp "c:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepdoc.dll" /primary /keyfile:MyCompany.snk /namespace:BCL.easyPDF8.Interop.EasyPDFDocument /out:BCL.easyPDF8.Interop.EasyPDFDocument.dll
tlbimp "c:\Program Files\Common Files\BCL Technologies\easyPDF 8\bepldr.exe" /primary /keyfile:MyCompany.snk /namespace:BCL.easyPDF8.Interop.EasyPDFLoader /out:BCL.easyPDF8.Interop.EasyPDFLoader.dll

You can ship these DLLs with your own product. These DLLs that you generate are considered your own code, they do not belong to BCL Technologies.

In order to use them, simply add them to your project using Visual Studio's Add Reference menu, then manually browse for the location of these DLLs.

Optionally, you may install them to the Global Assembly Cache, although this is not necessary:

regasm.exe BCL.easyPDF8.Interop.EasyPDFPrinter.dll
gacutil.exe /i BCL.easyPDF8.Interop.EasyPDFPrinter.dll
regasm.exe BCL.easyPDF8.Interop.EasyPDFProcessor.dll
gacutil.exe /i BCL.easyPDF8.Interop.EasyPDFProcessor.dll
regasm.exe BCL.easyPDF8.Interop.EasyPDFConverter.dll
gacutil.exe /i BCL.easyPDF8.Interop.EasyPDFConverter.dll
regasm.exe BCL.easyPDF8.Interop.EasyPDFDocument.dll
gacutil.exe /i BCL.easyPDF8.Interop.EasyPDFDocument.dll
regasm.exe BCL.easyPDF8.Interop.EasyPDFLoader.dll
gacutil.exe /i BCL.easyPDF8.Interop.EasyPDFLoader.dll

The commands for uninstallation from the Global Assembly Cache:

gacutil.exe /u BCL.easyPDF8.Interop.EasyPDFPrinter
gacutil.exe /u BCL.easyPDF8.Interop.EasyPDFProcessor
gacutil.exe /u BCL.easyPDF8.Interop.EasyPDFConverter
gacutil.exe /u BCL.easyPDF8.Interop.EasyPDFDocument
gacutil.exe /u BCL.easyPDF8.Interop.EasyPDFLoader

Once again, all of these are included as part of the standard easyPDF SDK for .NET 4.x.

If you prefer to have an official easyPDF SDK build with .NET 3.5 Interop DLLs, you may request a custom build from us.

Note, however, that .NET 3.5 is no longer supported by Microsoft. These automatically generated COM Interop DLLs do not contain Company and Copyright metadata, unless they are generated for .NET 4.x. Without Company and Copyright metadata, your product cannot be certified by Microsoft. If you are targeting .NET 3.5 or older, your COM Interop DLLs cannot possibly contain Company and Copyright metadata. For this reason we cannot ship .NET 3.5 Interop DLLs, unless they are specifically requested by customers.

An alternative solution is to use our new Native .NET API, which does not require COM registration or .NET COM Interop DLLs. Our Native .NET API is written entirely in C#, and it is far superior to the classic COM objects. It uses named pipes to communicate with the bulk of easyPDF SDK, which is written in C++, not in C#.