// Copyright (c) 2021 ActivePDF, Inc. // ActivePDF Toolkit 2018 // Example generated 01/24/21 using 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. class Examples { public static void Example() { string strPath; int intOpenOutputFile; string strSQL; string strConn; int intLoadDBMapFile; int intDBToForm; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath + "new.pdf"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } // 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) { ErrorHandler("LoadDBMapFile", intLoadDBMapFile); } // 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) { ErrorHandler("DBToForm", intDBToForm); } // Clear and close used queries oTK.ClearQueries(); // Close the output file oTK.CloseOutputFile(); // Release Object oTK.Dispose(); // Process Complete WriteResults("Done!"); } // Error Handling public static void ErrorHandler(string strMethod, object rtnCode) { WriteResults(strMethod + " error: " + rtnCode.ToString()); } // Write output data public static void WriteResults(string content) { // Choose where to write out results // Debug output //System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content); // Console Console.WriteLine(content); // Log file //using (System.IO.TextWriter writer = new System.IO.StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + "application.log", true)) //{ // writer.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content); //} } }