Create a PDF with Your Layout

Generate a PDF from your own form layout with a VBA macro. The example writes tformer-output.pdf to your temporary directory.

Setup: COM installation and setup. For a supplied project and layout, see the Quick Start.

Use this task-oriented COM workflow:

  1. Reference the installed TFORMer type library for early-bound VBA, or create the registered COM object by ProgID for late binding.
  2. Create the TFORMer COM object.
  3. Create a print job.
  4. Select the stand-alone form layout or repository/form combination.
  5. Create job-data records and assign DataField values.
  6. Select the output type and destination.
  7. Call PrintForm.

For optional settings such as image resolution, set Job.Options before generating output; see Output Options.

Before running the VBA example below, create a stand-alone .tff file in TFORMer Designer or use an existing one. Replace C:\path\to\layout.tff with its path and NAME_OF_YOUR_DATAFIELD with the exact name of a data field used by that layout. See Designer documentation and the installed Windows samples and templates. For the steps to open the VBA editor and run the example, see Microsoft Visual Basic for Applications (VBA).

Private Sub CreatePdf()
    Const PdfFileOutput As Long = 6

    Dim tformer As Object
    Dim printJob As Object
    Dim jobData As Object

    Set tformer = CreateObject("TFORMer9Lib.TFORMer")
    Set printJob = tformer.CreateJob
    Set jobData = printJob.NewJobDataRecordSet

    printJob.RepositoryName = "C:\path\to\layout.tff"

    jobData.AddNewRecord
    jobData.SetDataField "NAME_OF_YOUR_DATAFIELD", "Value"

    printJob.OutputName = Environ$("TEMP") & "\tformer-output.pdf"
    printJob.PrinterType = PdfFileOutput
    printJob.PrintForm
End Sub

Add the procedure to a VBA module and call CreatePdf from that module, following your application's macro-security policy. On success, open tformer-output.pdf in the current user's temporary directory, returned by Environ$("TEMP").

The example uses late binding. For early binding, see VBA setup.

After use, you can release the object references explicitly with Set printJob = Nothing and Set tformer = Nothing.

Search documentation

Search in
More scopes
Additional scopes

All contents