Running AutoBookmark from a Command-Line BAT File

AutoBookmark for Adobe® Acrobat®

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 PDF document processing by starting the processing from another application or Windows Task Scheduler. This functionality is available in version 7.3 and up. Bookmark and Page Sorting command was added in version 8.9.2.
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 the plug-in's menu(s) to configure a particular AutoBookmark operation you want to execute from a BAT file. This allows you to automate PDF tasks from the Windows command line, integrate PDF processing into scripts and scheduled workflows, and run the same configuration across multiple PDF documents without manual interaction. After configuring an operation, use its generated command name in your BAT file, Powershell script, Microsoft Power Automate Desktop App, Windows Task Scheduler, Python script, custom application or via any other automation tool. Here is the list of the operations that are supported for BAT file execution and corresponding command names:
  • Generate PDF Bookmarks from Text Styles
  • Bookmark Text Patterns
  • Bookmark Words from List
  • Create PDF Bookmarks from Text File
  • Generate PDF Links from Dictionary
  • Generate PDF Links by Text Search
  • Generate PDF Links by Using Rules
  • Highlight PDF Text by Search
  • Highlight Text Pattern
  • Create Table of Contents (TOC) from PDF Bookmarks
  • Sort PDF Bookmarks and Pages
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
  • Sort Bookmarks and Pages - *.bmsort
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\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.
32-bit vs 64-bit Acrobat
Make sure to enter a correct file path to the version of Adobe Acrobat installed on your computer. If you are running 32-bit legacy Adobe Acrobat, then the path is C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe. If you are running 64-bit Adobe Acrobat, then the default path is C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe.
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
  • Sort Bookmarks and Pages - AutoBookmark_SortBookmarks
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\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\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.
Example for "Create Table of Contents" operation
This is an example of running "Create Table of Contents" operation on a specific file:
SET AUTOBOOKMARK_INPUT_FILE=c:\Data\InputDocument.pdf
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\TOCSettings.toc
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\
SET AUTOBOOKMARK_OUTPUT_PREFIX=
SET AUTOBOOKMARK_OUTPUT_SUFFIX= with TOC
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
SET AUTOBOOKMARK_BAT_ENABLE=ON
SET AUTOBOOKMARK_MODE=AutoBookmark_TOCFromBookmarks
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
The above BAT file will add table of contents from bookmarks to C:\Data\InputDocument.pdf file using C:\Data\TestSettings.toc settings file and save resulting PDF files as C:\Data\Filename with TOC.pdf. Processing details will be saved into C:\Data\AutoBookmarkLog.txt file.
Example for "Sort Bookmarks and Pages" operation
This is an example of running Sort Bookmarks and Pages operation on a specific file:
SET AUTOBOOKMARK_INPUT_FILE=c:\Data\InputDocument.pdf
SET AUTOBOOKMARK_CONFIG_FILE=C:\Data\SortSettings.bmsort
SET AUTOBOOKMARK_OUTPUT_FOLDER=C:\Data\
SET AUTOBOOKMARK_OUTPUT_PREFIX=
SET AUTOBOOKMARK_OUTPUT_SUFFIX= with Sorting
SET AUTOBOOKMARK_LOG_FILE=C:\Data\AutoBookmarkLog.txt
SET AUTOBOOKMARK_BAT_ENABLE=ON
SET AUTOBOOKMARK_MODE=AutoBookmark_SortBookmarks
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
The above BAT file will add table of contents from bookmarks to C:\Data\InputDocument.pdf file using C:\Data\SortSettings.bmsort settings file and save resulting PDF files as C:\Data\Filename with Sorting.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:
Running AutoBookmark via Powershell
Here is an example of running Sort Bookmarks and Pages operation via Powershell script. Save the script as *.ps1 file (do not forget to change environment variables to point to actual files on your system), right-click on the file in Windows Explorer and select Run with Powershell.
# Set environment variables
$env:AUTOBOOKMARK_INPUT_FILE = "c:\Data\InputDocument.pdf"
$env:AUTOBOOKMARK_CONFIG_FILE = "C:\Data\Sort.bmsort"
$env:AUTOBOOKMARK_OUTPUT_FOLDER = "C:\Data\"
$env:AUTOBOOKMARK_OUTPUT_PREFIX = ""
$env:AUTOBOOKMARK_OUTPUT_SUFFIX = " with Sorting"
$env:AUTOBOOKMARK_LOG_FILE = "C:\Data\AutoBookmarkLog.txt"
$env:AUTOBOOKMARK_BAT_ENABLE = "ON"
$env:AUTOBOOKMARK_MODE = "AutoBookmark_SortBookmarks"

# Execute Adobe Acrobat natively using the Call operator (&)
& "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
Running AutoBookmark from Python script
Here is an example of running Sort Bookmarks and Pages operation via Python script. Save the script as *.py file (do not forget to change environment variables to point to actual files on your system). You can run Python script either via code editor or via command-line: python sort.py.

import os
import subprocess

# Set environment variables
os.environ["AUTOBOOKMARK_INPUT_FILE"] = r"c:\Data\InputDocument.pdf"
os.environ["AUTOBOOKMARK_CONFIG_FILE"] = r"C:\Data\Sort.bmsort"
os.environ["AUTOBOOKMARK_OUTPUT_FOLDER"] = r"C:\Data\\"
os.environ["AUTOBOOKMARK_OUTPUT_PREFIX"] = ""
os.environ["AUTOBOOKMARK_OUTPUT_SUFFIX"] = " with Sorting"
os.environ["AUTOBOOKMARK_LOG_FILE"] = r"C:\Data\AutoBookmarkLog.txt"
os.environ["AUTOBOOKMARK_BAT_ENABLE"] = "ON"
os.environ["AUTOBOOKMARK_MODE"] = "AutoBookmark_SortBookmarks"

acrobat_path = r"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
arguments = ["/n", "/h"]

try:
    # Removed check=True so non-zero codes do not raise an exception
    result = subprocess.run([acrobat_path] + arguments, capture_output=True, text=True)
    
    # Print the exit code for your tracking, without crashing
    print(f"Acrobat process finished. Exit code: {result.returncode}")

except FileNotFoundError:
    print(f"Error: Could not find Acrobat executable at: {acrobat_path}")
Running 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\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();