Example code is for an older version of Toolkit, newer code is available.
# Copyright (c) 2021 ActivePDF, Inc.
# ActivePDF Toolkit 2017
# Example generated 01/25/21
require 'win32ole'
# Get current path
strPath = File.expand_path(File.dirname(__FILE__)) + "\\"
# Instantiate Object
oTK = WIN32OLE.new("APToolkit.Object")
# Create the new PDF file
intOpenOutputFile = oTK.OpenOutputFile(strPath + 'new.pdf')
if intOpenOutputFile != 0
puts "Error in OpenOutputFile: #{intOpenOutputFile}"
end
# 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'.to_s + ';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
puts "Error in LoadDBMapFile: #{intLoadDBMapFile}"
end
# 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
puts "Error in DBToForm: #{intDBToForm}"
end
# Clear and close used queries
oTK.ClearQueries()
# Close the output file
oTK.CloseOutputFile()
# Release Object
oTK = ''
# Process Complete
puts "Done!"