Running Mail Merge from a Command-Line BAT File
AutoMailMerge for Adobe® Acrobat®
- Introduction
- It is possible to execute a mail merge job from outside of Adobe Acrobat via a command-line BAT file. Use this method to automate mail merge operation by starting the processing from an another application or Windows Task Scheduler. You would need to configure the mail merge job using a regular method (via a user interface) prior to running it via a BAT file. This functionality is available in version 3.4 and up.
- Configure a Mail Merge Job
- Open a PDF form file and use “Plug-ins > Mail Merge...” menu to configure a complete mail merge job using regular application interface.
- Save the Mail Merge Settings
- Save mail merge settings as *.mms file by clicking “Save Settings” button located on the main AutoMailMerge screen. The mail merge settings file stores all parameters required for the job such as data source, field mappings and processing options.
- Create a BAT File
- Use any plain text editor (such as Notepad) to create a blank text file. Add the following 3 lines to the file. Make sure to replace paths and filenames with the actual filenames you are using. The example below shows how to start Acrobat DC and fill FormTemplate.pdf PDF form using the mail merge settings from Settings.mms file.
- Here is an example of BAT file for 64-bit Adobe Acrobat:
-
SET AUTOMAILMERGE_FORM=C:\Data\FormTemplate.pdf
SET AUTOMAILMERGE_CONFIG=C:\Data\Settings.mms
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n
- Here is an example of BAT file for 32-bit Adobe Acrobat:
-
SET AUTOMAILMERGE_FORM=C:\Data\FormTemplate.pdf
SET AUTOMAILMERGE_CONFIG=C:\Data\Settings.mms
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n
- The environment variable AUTOMAILMERGE_FORM is used to specify a full file path to the PDF form that needs to be used for the job while AUTOMAILMERGE_CONFIG specifies a full file path to the MMS settings file.
- Save a BAT File
- Save the BAT file with *.bat file extension. Make sure to select a proper file filter in the "Save As" dialog in Notepad to avoid saving the file with a default *.txt file extension.
- Run a BAT File
- The mail merge job can be executed by double-clicking on the BAT file in Windows File Explorer window or by running it from another application.
- Please note that the BAT file will open Adobe Acrobat and display a progress window during the processing. Use /h switch on the Acrobat's command line to optionally run Adobe Acrobat minimized:
- Here is an example of BAT file for 64-bit Adobe Acrobat:
-
SET AUTOMAILMERGE_FORM=C:\Data\FormTemplate.pdf
SET AUTOMAILMERGE_CONFIG=C:\Data\Settings.mms
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
- Starting Mail Merge from a C# Application
- It is also possible to execute a mail merge job from another application. Here is a sample C# code that shows how to launch Adobe Acrobat and pass all necessary parameters via the environmental variables.
-
System.Diagnostics.Process firstProc = new System.Diagnostics.Process();
firstProc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe";
firstProc.EnableRaisingEvents = true;
firstProc.StartInfo.UseShellExecute = false;
firstProc.StartInfo.Arguments = @"/n /h"; // pass command-line parameters
firstProc.StartInfo.EnvironmentVariables.Add("AUTOMAILMERGE_FORM", @"C:\Data\FormTemplate.pdf");
firstProc.StartInfo.EnvironmentVariables.Add("AUTOMAILMERGE_CONFIG", @"C:\Data\Settings.mms");
firstProc.Start();