Auto-Renaming PDF Files from a Command-Line BAT File

AutoSplit Pro™ plug-in for Adobe® Acrobat®

Introduction
Manual renaming of multiple PDF files based on a document content is often a slow process. This tutorial explains how the AutoSplit™ plug-in can be used to rename files automatically, using a command-line BAT file (also known as a batch file). A batch file is a script file in Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. BAT files are typically used to control and automate execution of other applications. Using a batch file allows starting an auto-renaming "job" from outside of Adobe Acrobat without any user interaction. The BAT file starts Adobe Acrobat and passes 'instructions' for renaming specific files or all files in a folder according to a user-specified renaming method. BAT files can be executed by by batch scheduling or hot-folder monitoring applications. The renaming configuration needs to be made in AutoSplit using regular file renaming methods before to being used within a BAT file.
Input Files and Renaming Method
The sample files used here are invoices named only by each customer name. All invoices follow an identical format and contain an 'Invoice number' located somewhere on the first page. We will use the plug-in to create a *.docren settings file containing instructions on how to rename files using this number. These settings will then be included as part of the command-line BAT file, so that any input files (invoices) processed by the BAT file will be renamed according to these instructions. All output invoices will be named using their corresponding 'invoice number'.
Prerequisites
You need a copy of Adobe® Acrobat® along with the AutoSplit plug-in installed on your computer in order to use this tutorial. Both are available as trial versions.

Configuring Renaming Settings

Step 1 - Open the “Auto-Rename PDF Files” Menu
The first step is to configure file renaming settings and save these as a settings file. To do this, begin by opening the "Auto-Rename PDF Files..." tool. Close all PDF documents open in Acrobat first to avoid possible file access conflicts. Then select “Plug-ins > Auto-Rename PDF Files…” from the main Acrobat menu.
Step 2 - Add a New Filename Component
Press “Add…” to add a new component to the output file name.
Step 3 - Select a Filenaming Option
Here, select a suitable option for renaming files appropriately. In this example, we will configure the plug-in to rename invoices using the invoice number located on page 1 of each document, using the 'text search' method. Select the “Text By Search” option and click “Next” to enter parameters.
Step 4 - Enter a Search Expression
In the "Find Text" dialog, configure search parameters for locating text within documents that is to be used as a filename component. Enter a relevant search expression in the "Find what:" entry box. In this example, we'll use the expression "Invoice number: \d+" to locate the invoice numbers in each invoice.
This expression consists of the text to search for ("Invoice number:") which will be followed by a number consisting of one or more digits, as indicated by "\d+" - with the "+" indicating 'one or more' as the invoice numbers may vary in length.
This expression will also extract the "Invoice number:" text as well as the corresponding number. (As ":" is not a permitted symbol for use in filenames, they are automatically replaced with an underscore "_".)
Step 5 - Confirm Search Expression Options
Confirm necessary options such as "Match whole words only" or "Match case" - in this example, both are left unchecked ("Invoice number/date" text is uppercase in these sample documents, but the expression would still work if the text case was inconsistent across all files being renamed).
Optionally, add components to search expressions via the "Add Search Item..." button. This opens a dialog containing a detailed list of template search items that can be selected according to the user's requirements.
Click "OK" to proceed.
Step 6 - Configure Further Options
The filenaming component will now be listed. Optionally, add more components and use the buttons available to order them, or click on the "Options..." button to specify renaming "rules".
Step 7 - Select an Output Location and Save the Configuration
Optionally, check the "Move successfully renamed files to another folder" option. This activates the "Select Output Folder..." button. Press it to specify an output folder for the renamed files to be placed in after the renaming operation has been executed via this configuration. This means that files renamed using the 'hot' folder will be automatically placed into this specified output location after processing.
Now use the "Save Settings..." button to save this entire renaming method as a *.docren settings file.
Step 8 - Select a Location
Select a suitable location and name the *.docren settings file before pressing "Save".

Creating and Using Command-Line BAT File

Step 1 - Creating a BAT File
Create a BAT file using any plain text editor (such as Notepad). Begin by creating a blank text file, then add the following lines making sure to replace file paths and filenames with the relevant filenames you are using:
SET AUTOSPLIT_INPUT_FOLDER=c:\Data\HotFolder
SET AUTOSPLIT_CONFIG_FILE=C:\Data\RenamingSettings.docren
SET AUTOSPLIT_BAT_ENABLE=ON
SET AUTOSPLIT_MODE=RenameFile
SET AUTOSPLIT_LOG_FILE=C:\Data\HotFolder\AutoSplitLog.txt
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
The above BAT will apply RenamingSettings.docren settings to every file inside c:\Data\HotFolder folder. Please see the following page for details on how to write BAT file for AutoSplit.
There are 3 available modes how the BAT file can be applied to files:
  1. Run on all PDF files in a folder (use AUTOSPLIT_INPUT_FOLDER variable)
  2. Run on a specific PDF file (use AUTOSPLIT_INPUT_FILE variable)
  3. Pass filename or folder name as a parameter to a BAT file
The AUTOSPLIT_INPUT_FOLDER variable is used to specify a full file path to the 'hot' folder containing the files that need to be processed.
"AUTOSPLIT_CONFIG_FILE" specifies a full file path to the renaming settings file created in steps 1-8 (RenamingSettings.docren).
The "AUTOSPLIT_MODE" variable specifies the processing 'type' - "RenameFile" instructs the plug-in that it is a renaming operation.
Use the AUTOSPLIT_LOG_FILE variable to specify a log file location, useful for troubleshooting and record keeping. If a log file does not exist, it will be automatically created. If a log file already exists, then new records will be appended to the file.
Step 2 - Saving the BAT File
Press "File > Save As..." to save the text as a BAT file.
By default, Notepad prompts to save as a *.txt file. Use the "Save as type:" list to select "All Files". Save the BAT file with a suitable name and location using the correct *.bat file extension. Press "Save" to save the file.
Step 3 - Executing the BAT File
Place suitable documents that are to be renamed according to the *.docren settings into the 'Hot Folder' location, as indicated by the "AUTOSPLIT_INPUT_FOLDER" line of the BAT file. In this example, we have placed multiple invoices following the same format into a folder titled "HotFolder".
At this stage, the BAT file can still be edited if necessary by right clicking on it and pressing "Edit" to open it in Notepad.
When ready to use it to rename the files in the 'hot' folder, double-click on the BAT file to run it.
Step 4 - Check the Results
After processing, the renamed files will be placed in the specified output location. Open the folder to inspect the filenames.
The files will have been renamed according to the user specified settings.
Step 5 - Inspect the Log File
According to this sample BAT file created in step 1, the log file will have been created and saved within the 'hot' folder location. Open the file to inspect its contents.
The log file details all input files and their corresponding output names along with the settings used for renaming. It can be kept for troubleshooting renaming issues, as well as being a detailed record for the renaming procedure.

Monitoring a Hot-Folder

Please see the next tutorial on how to monitor a folder and execute a BAT file on every PDF file that is placed into it.
You can find more AutoSplit tutorials here.