COM and VBA
COM API Reference — Types, members and enumerations.
New to TFORMer? Create your first PDF with the COM / Excel VBA Quick Start. It includes a ready-to-import module and its form layout. Continue here for general COM use, Word/Access setup and additional examples.
Introduction
The TFORMer COM interface is available on Windows for automation clients that support COM. Typical integrations include Microsoft Office applications through Visual Basic for Applications (VBA) and scripts executed by Windows Script Host, such as VBScript.
The TFORMer SDK setup installs and registers the COM component and includes Microsoft Office and VBScript samples. Select these components as described in Installation on Microsoft Windows.
Use the COM component matching the client application's architecture (32-bit or 64-bit), not just the operating system. See COM DLLs and registration for deployment.
COM registration details
- The installed type library is named TFORMer
9Runtime Type Library. - Type-library GUID:
{7709C4E4-4641-4B08-8BA6-8649E3672C32} - ProgID of the main TFORMer COM class:
TFORMer9Lib.TFORMer - CLSID of the main TFORMer COM class:
{AEB782F4-D12D-485F-BF49-1D602BD74BF8}
Use a Configured Data Source
Select the ODBC source in the supplied picking-list layout, set PickingListParameter to 2, and write a PDF. The layout's stored query uses this parameter to select that picking list; the application does not supply a separate SQL statement or modify the database. For definition settings, field mappings and parameter rules, see Data Sources Defined in a Layout.
For a configured CSV source instead, adapt this program to choose the CSV file at runtime.
Before You Run
- Set up the SDK for your language, including its native runtime and matching process architecture.
- Locate
(6) Samples_Picking List.tffin the SDK's Templates folder. The default Windows location is%ProgramData%\TEC-IT\TFORMer\9\Templates. - The layout uses
DSN=TFORMer_Sample;, useradmin, tabletbl_PickingList, and the predefined parameterPickingListParameter. Its driver and DSN must match the application's architecture. - The sample database is
ODBCReportPDF.mdb, installed under%ProgramData%\TEC-IT\TFORMer\9\Examples\Command Line\ODBCReportPDF. The sample DSN must point to this database. This particular example uses the Windows Access ODBC driver; it is not a Linux setup example. - Choose a new PDF path in an existing writable directory. The program refuses to overwrite an existing output file.
Run the Example
Pass the full layout path and PDF path as the two command-line arguments.
This complete example uses VBScript, not an Excel VBA module. Save it as ConfiguredSource.vbs and run cscript //nologo ConfiguredSource.vbs followed by the two quoted paths. Use Windows Script Host with the registered TFORMer9Lib.TFormer component. For the ODBC example, the driver and DSN must match the script host's architecture. See Windows SDK installation if the COM component is unavailable.
NewJobDataDataSource(...) creates the data object and attaches it to the job; no separate assignment is needed. The PDF constant is included below.
Complete Example
Option Explicit
Const PrinterType_PdfFile = 6
If WScript.Arguments.Count <> 2 Then
WScript.Echo "Usage: cscript //nologo ConfiguredSource.vbs <layout.tff> <output.pdf>"
WScript.Quit 1
End If
Dim files, layout, output, sdk, job, data
Set files = CreateObject("Scripting.FileSystemObject")
layout = files.GetAbsolutePathName(WScript.Arguments(0))
output = files.GetAbsolutePathName(WScript.Arguments(1))
If Not files.FileExists(layout) Then
WScript.Echo "Layout not found: " & layout
WScript.Quit 1
End If
If files.FileExists(output) Then
WScript.Echo "Choose a new output file: " & output
WScript.Quit 1
End If
Set sdk = CreateObject("TFORMer9Lib.TFormer")
Set job = sdk.CreateJob
job.RepositoryName = layout
' This factory creates the data object AND attaches it to the job.
Set data = job.NewJobDataDataSource("ODBC")
data.SetParameterValue "PickingListParameter", "2"
' Generate a PDF; no physical printer is used.
job.PrinterType = PrinterType_PdfFile
job.OutputName = output
job.PrintForm
Set data = Nothing
Set job = Nothing
Set sdk = Nothing
If Not files.FileExists(output) Then
WScript.Echo "No PDF was created: " & output
WScript.Quit 1
End If
If files.GetFile(output).Size = 0 Then
WScript.Echo "The PDF is empty: " & output
WScript.Quit 1
End If
WScript.Echo "Created PDF: " & output
Check the Result
Open the PDF at the path reported by the program. Check that it contains picking list 2, not the layout parameter's default selection 1. Evaluation output may include a demo marking.
If no PDF is produced, check the reported error, layout path, ODBC driver, DSN and database before changing the parameter value. For the other data-input mechanisms, see Providing Job Data.
To supply the ODBC connection and SQL directly in code instead, use IJob.NewJobDataOdbc. See the IJobDataOdbc example in the COM API reference; no named data source in the layout is required for that approach.
Apply a License
After creating the tformer object in Create a PDF with Your Layout, apply your license before calling an output method:
tformer.LicenseBase64 "BASE64_LICENSE_DATA_FROM_TEC_IT"
Replace the placeholder with the Base64 license data supplied by TEC-IT and keep it confidential. If the call raises an error, handle it before proceeding to output. See Licensing for file-based licensing and redistribution guidance.
Set Up VBA in Microsoft Office
The Office application's macro-security policy must permit the VBA code to run. Follow your organization's policy; do not disable macro security globally.
To try the late-bound PDF example in desktop Office on Windows:
- Open your document or workbook in Word or Excel. Select Developer > Visual Basic, or press
Alt+F11. If the Developer tab is hidden, enable Developer under File > Options > Customize Ribbon. In Access, open your database and select Database Tools > Visual Basic, or pressAlt+F11. - In the VBA editor, select Insert > Module and paste the
CreatePdfprocedure into the module. - Adapt the layout path and data-field name. Place the cursor inside
CreatePdfand pressF5to run it, subject to the macro-security policy above. - Open
tformer-output.pdfin the current user's temporary directory. To retain the code in Word or Excel, save in a macro-enabled format such as.docmor.xlsm.
This late-bound example needs no type-library reference. For early binding, select Tools > References in the VBA editor and enable the installed TFORMer 9 Runtime Type Library. Then use the library's declared types and enumerations instead of late-bound Object variables and numeric constants. Early binding provides IntelliSense and compile-time type checking.
Reference and Sample Links
Use the COM API Reference to look up types and members, and Samples and Downloads for examples. See Interface Guides and API References for installed documentation locations.