Running AutoBookmark from a Command-Line BAT File
Introduction
It is possible to run some AutoBookmark Pro operations from outside of Adobe Acrobat via a command-line BAT file. Use this method to automate document processing by starting the processing from another application or Windows Task Scheduler. This functionality is available in version 7.3 and up.
You would need to configure the particular AutoBookmark operation via user interface prior to running it via a BAT file and save settings into a file. Once you have a settings file it can be used for starting the job from a command-line file.
Configure AutoBookmark Operation
Use plug-in's menu(s) to configure a particular AutoBookmark operation you want to execute from a BAT file. Here is the list of the operations that are supported for the BAT file execution and corresponding command names:
  • Generate Bookmarks from Text Styles
  • Bookmark Text Patterns
  • Bookmark Words from List
  • Create Bookmarks from Text File
  • Generate Links from Dictionary
  • Generate Links by Text Search
  • Generate Links by Rules
  • Highlight Text by Search
  • Highlight Text Pattern
  • Create TOC from Bookmarks
Save the Processing Settings
Each of the above mentioned operations provides a way to save processing parameters as a settings file. For example, for "Generate Bookmarks from Text Styles" use "Save..." button to save settings as *.abm settings file. All other operations have a set of "Save" and "Load" buttons for saving settings into a file.
Here is a list of settings file extensions for each operation:
  • Generate Bookmarks from Text Styles - *.abm
  • Bookmark Text Patterns - *.abtp
  • Bookmark Words from List - *.ablist
  • Create Bookmarks from Text File - *.abtxt
  • Generate Links from Dictionary - *.abdict
  • Generate Links by Text Search - *.linksgen
  • Generate Links by Rules - *.linksrules
  • Highlight Text by Search - *.highlights
  • Highlight Text Pattern - *.hltpattern
  • Create TOC from Bookmarks - *.toc
Create a BAT File
Use any plain text editor (such as Notepad) to create a blank text file. Add the following 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 apply "Generate Bookmarks from Text Styles" operation to Test.pdf PDF file (located inside C:\Data folder) using the settings from Settings.abm file.
SET AUTOBOOKMARK_INPUT_FILE=c:\Data\Test.pdf
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\Settings.abm
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\Output
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
SET AUTOBOOKMARK_BAT_ENABLE=ON
SET AUTOBOOKMARK_MODE=AutoBookmark_GenerateBookmarks
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
Resulting PDF file will be saved into C:\Data\Output folder as specified by AUTOBOOKMARK_OUTPUT_FOLDER variable.
Specifying Input Files
The environment variable AUTOBOOKMARK_INPUT_FILE is used to specify a full file path to the PDF file that needs to be used for the job while AutoBookmark_CONFIG_FILE specifies a full file path to the settings file. Use AUTOBOOKMARK_INPUT_FOLDER to specify an input folder. All PDF files from this folder will be processed by the operation.
Here is an example of selecting a folder (C:\Data\Input) for processing:
SET AUTOBOOKMARK_INPUT_FOLDER=c:\Data\Input
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\Settings.abm
Specifying Processing Operation
The environment variable AUTOBOOKMARK_MODE is used to specify a processing operation. Here is the list of the supported values:
  • Generate Bookmarks from Text Styles - AutoBookmark_GenerateBookmarks
  • Bookmark Text Patterns - AutoBookmark_BookmarkTextPatterns
  • Bookmark Words from List - AutoBookmark_BookmarkFromList
  • Create Bookmarks from Text File - AutoBookmark_BookmarksFromTextFile
  • Generate Links from Dictionary - AutoBookmark_CreateLinksFromDictionary
  • Generate Links by Text Search - AutoBookmark_CreateLinksBySearch
  • Generate Links by Rules - AutoBookmark_CreateLinksByRules
  • Highlight Text by Search - AutoBookmark_HighlightTextBySearch
  • Highlight Text Pattern - AutoBookmark_HighlightTextPattern
  • Create TOC from Bookmarks - AutoBookmark_TOCFromBookmarks
Here is an example of setting the AUTOBOOKMARK_MODE variable:
SET AUTOBOOKMARK_MODE=AutoBookmark_GenerateBookmarks
Saving Output Files
The processing results need to be saved into a different PDF file. The input files on disk are never modified directly. You can specify an output folder where to save the resulting PDF file, and optional file prefix and suffix that need to be added to the output filename.
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\Output
SET AUTOBOOKMARK_OUTPUT_PREFIX=Prefix
SET AUTOBOOKMARK_OUTPUT_SUFFIX= Suffix
The above instructions will save results as C:\Data\Output\PrefixFilenameSuffix.pdf file. Where Filename is the name of the input PDF file.
Saving a Log File
Add the following line to the BAT file to generate a processing log file (in plain text format). The log files are indispensable for the troubleshooting problems that often arise during the processing. You can view log file with any text editor.
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
Example for "Generate Links from Dictionary" operation
This is an example of running "Generate Links from Dictionary" operation on a specific file:
SET AUTOBOOKMARK_INPUT_FILE=c:\data\Test.pdf
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\Test.abdict
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\Output
SET AUTOBOOKMARK_OUTPUT_SUFFIX= Links from Dictionary
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
SET AUTOBOOKMARK_BAT_ENABLE=ON
SET AUTOBOOKMARK_MODE=AutoBookmark_CreateLinksFromDictionary
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
The above BAT file will generate links using C:\Data\Test.abdict settings file and save resulting PDF as C:\Data\Output\Test Links From Dictionary.pdf file. Processing details will be saved into C:\Data\AutoBookmarkLog.txt file.
Example for "Generate Links by Text Search" operation
This is an example of running "Generate Links by Text Search" operation on all files in a folder:
SET AUTOBOOKMARK_INPUT_FOLDER=c:\Data\Input
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\Test.linksgen
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\Output
SET AUTOBOOKMARK_OUTPUT_PREFIX=
SET AUTOBOOKMARK_OUTPUT_SUFFIX= Links by Search
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
SET AUTOBOOKMARK_BAT_ENABLE=ON
SET AUTOBOOKMARK_MODE=AutoBookmark_CreateLinksBySearch
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
The above BAT file will process all PDF files in C:\Data\Input folder using C:\Data\Test.linksgen settings file and save resulting PDF files as C:\Data\Output\Filename Links by Search.pdf. Processing details will be saved into C:\Data\AutoBookmarkLog.txt 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 processing 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 may display a progress bar during the processing. Use /h switch on the Acrobat's command line to optionally run Adobe Acrobat minimized:
Starting AutoBookmark from a C# Application
Here is a sample C# code that shows how to launch AutoBookmark from a .NET application and pass all necessary parameters via the environmental variables.
System.Diagnostics.Process firstProc = new System.Diagnostics.Process();
firstProc.StartInfo.FileName = @"C:\Program Files (x86)\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("AUTOBOOKMARK_INPUT_FILE", @"C:\Data\Test.pdf");
firstProc.StartInfo.EnvironmentVariables.Add("AUTOBOOKMARK_CONFIG_FILE", @"C:\Data\Settings.linksgen");
firstProc.StartInfo.EnvironmentVariables.Add("AUTOBOOKMARK_BAT_ENABLE", @"ON");
firstProc.StartInfo.EnvironmentVariables.Add("AUTOBOOKMARK_OUTPUT_FOLDER", @"C:\Data\Output");
firstProc.StartInfo.EnvironmentVariables.Add("AUTOBOOKMARK_MODE", @"AutoBookmark_CreateLinksBySearch");
firstProc.Start();