Example code is for an older version of Toolkit, newer code is available.
' Copyright (c) 2021 ActivePDF, Inc.
' ActivePDF Toolkit 2017
' Example generated 04/20/21
Imports System
' Make sure to add the ActivePDF product .NET DLL(s) to your application.
' .NET DLL(s) are typically found in the products 'bin' folder.
Public Class Examples
Sub Example()
Dim strPath As String, intOpenOutputFile As Integer, strSQL As String, strConn As String, _
intLoadDBMapFile As Integer, intDBToForm As Integer
strPath = AppDomain.CurrentDomain.BaseDirectory
' Instantiate Object
Dim oTK As APToolkitNET.Toolkit = New APToolkitNET.Toolkit()
' Create the new PDF file
intOpenOutputFile = oTK.OpenOutputFile(strPath & "new.pdf")
If intOpenOutputFile <> 0 Then
ErrorHandler("OpenOutputFile", intOpenOutputFile)
End If
' Specify the template form to populate
oTK.SetDBInputTemplate(strPath & "dbtemplate.pdf")
' Set query command to a variable
strSQL = "Select * From Supplier"
' Set connection String to a variable
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & "xtreme.mdb" & ";Persist Security Info=False"
' Set master query
oTK.SetMasterQuery(strConn, "Admin", "", -1, strSQL)
' Set the row Separator
oTK.SetDBMultiRowSeparator("")
' Related query separator is only needed if different from default of '|'
oTK.RelatedQuerySeparator = "|"
' Add related query
oTK.AddRelatedQuery(strConn, "Admin", "", -1, strSQL, true)
' If db column names are different then field names a map file is needed
' In this example only the zip/postal code is different
intLoadDBMapFile = oTK.LoadDBMapFile(strPath & "dbformmap.txt")
If intLoadDBMapFile <> 0 Then
ErrorHandler("LoadDBMapFile", intLoadDBMapFile)
End If
' Flatten fields that are populated with data
oTK.SetDefaultDBMergeFlag(-997)
' Flatten all other fields on the form
oTK.FlattenRemainingFormFields = 1
' Fill the template form
intDBToForm = oTK.DBToForm(false)
If intDBToForm <> 0 Then
ErrorHandler("DBToForm", intDBToForm)
End If
' Clear and close used queries
oTK.ClearQueries()
' Close the output file
oTK.CloseOutputFile()
' Release Object
oTK.Dispose()
' Process Complete
WriteResults("Done!")
End Sub
' Error Handling
' Error messages written to debug output
Sub ErrorHandler(ByVal strMethod, ByVal RtnCode)
WriteResults(strMethod + " error: " + rtnCode.ToString())
End Sub
' Write output data
Sub WriteResults(content As String)
' Choose where to write out results
' Debug output
'System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content)
' Console
Console.WriteLine(content)
' Log file
'Using tw = New System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory & "application.log", True)
' tw.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content)
'End Using
End Sub
End Class