Customizing Table of Contents Title
Introduction
This tutorial shows how to customize table of contents (TOC) title in PDF documents created by the AutoBookmark™ plug-in for the Adobe® Acrobat®. This tutorial focuses entirely on title customization, see the following tutorial for the instructions on how to automatically generate table of contents from PDF bookmarks.
Methods
There are two ways to customize a TOC title:
Use the first method if you need to insert document metadata properties into the TOC title. The standard (such as document "Title" or "Author")  and custom document metadata properties can be used. Use "File > Properties" menu in the Adobe® Acrobat® to view, edit or add custom document properties. Properties are commonly used to specify document's title, subject and author.
The example below shows a 3-line title that is generated using "Title", "Author" and "Subject" properties with each line using a different text style:
Metadata example
For more complex customizations, use Acrobat JavaScript scripting method to change both the content and the visual appearance of the title. The script can use all functionality provided by the Acrobat JavaScript language to compose the text of the title. It can utilize metadata properties, file names, form fields text, bookmarks and any other element of the PDF document.
Note that that customization with metadata and JavaScript is not available when generating a master TOC for multiple PDF documents, because there is no single PDF that can be used to extract the properties from. However, all style keywords are available for the master TOC.
This operation is available in the Action Wizard (Acrobat's batch processing tool) with the AutoBookmark™ Pro plug-in and can be used for automating of document processing workflows.
Prerequisites
You need a copy of the Adobe® Acrobat® along with the AutoBookmark™ plug-in installed on your computer in order to use this tutorial. You can download trial versions of both the Adobe® Acrobat® and the AutoBookmark™ plug-in.
Method 1 - Customizing TOC Title with Document Properties
Step 1 - Open the "Table Of Contents Settings" Dialog
Start the Adobe® Acrobat® application and open a PDF document with bookmarks using "File > Open..." menu.
Open a PDF document
Select "Plug-Ins > Table of Contents > Create TOC from Bookmarks..." in the main menu to open the "Table Of Contents Settings" dialog.
Open the Table Of Contents Settings dialog
Step 2 - Customize TOC Title with Metadata Properties
Type a text into the "Title:" box located on the "Style" tab of the "Table Of Contents Settings" dialog.
Type text into Title box
Using Document Properties
The standard document properties such as Author, Subject, Title, Keywords, Creator, Producer, CreationDate, ModDate are accessible via the "Description" tab of the "Document Properties" dialog (use "File > Properties" menu in Adobe Acrobat to access it). Only Author, Title, Subject, and Keywords properties are editable. The rest of the properties are automatically set at the time the document is created or modified. Use "Custom" tab to add custom properties to the PDF document. Both standard and custom properties can be used in the TOC title. Note that property names are case-sensitive.
Standard PDF Metadata Properties:
  • {Title}
  • {Author}
  • {Subject}
  • {Keywords}
  • {Creator}
  • {Producer}
  • {CreationDate}
  • {ModDate}
For example, type {Title} by {Author} text into the "Title:" box. It will combine "Title" and "Author" metadata properties into a custom title. This expression can produce custom titles such as "Reference Manual by John Doe" or, as in the example below, "Acrobat PDF Consultant by Adobe Developer Support".
Using Metadata Properties
Customizing Text Style
It is possible to change a text color and font size within the title string, but only on the per-line basis. It means only a single color and text font can be used within a single line of text, although text can overflow into multiple lines if the it does not fit into the space available. Multiple different keywords can be used on the same line. The position of the keyword within the line does not matter. It can appear anywhere in the text. Note that all keywords apply only to a single line of text and revert to the default title style on the next line.
Use {fontsize:XX} to change the font size of the current font to the value of XX, where XX is any integer that represents a valid font size. For example, "{fontsize:20}" - sets the font size to 20 pt.
Use {textcolor:R,G,B} to set a custom text color for the text, where R, G and B are numbers between 0 and 255. These numbers represent intensity of the Red, Green and Blue components of the color. For example, {textcolor:0,0,255} - sets the color of the text to blue.
Use {fontname:Font Name} to change font for the current text line. For example, {fontname: Segoe UI Black} - sets the "Segoe UI Black" as a current font.
Here is the example of the TOC title with the multiple keywords string {Title}{fontsize:20}{textcolor:0,0,255}{fontname: Segoe UI Black}:
Customizing Text Style
Adding Horizontal Divider
Use {drawline:T,Y} to draw a horizontal line from the left to the right margin. Parameters: T - is a line thickness in points (1 inch is 72 points), Y - is a vertical offset of the line from the current text baseline also measured in points. It can be positive or negative. Positive offset moves the line below the text line, while negative moves the line above it. The line is drawn using a current text color.
For example, type {drawline:4,10}{Title} to draw a line 4 pt thick with a vertical offset of 10 points. It will output TOC title with a line draw 10 points below the text baseline.
Adding Horizontal Divider
Multi-Line Table of Contents
The following example uses various keywords to customize a multi-line table of contents with different text styles and a horizontal divider:
Table of Contents
{fontsize:16}{fontname:Segoe UI Black Italic}{Title}
{drawline:10,0}{fontsize:8}{textcolor:0,128,255}
Here is the resulting output:
Multi-Line Table of Contents
Step 3 - Generate Table of Contents
Specify the rest of the settings and click "OK" to generate table of contents.
Generate Table of Contents
Method 2 - Customizing TOC Title with Acrobat JavaScript
Step 1 - Open the "Table Of Contents Settings" Dialog
Start the Adobe® Acrobat® application and open a PDF document with bookmarks using "File > Open..." menu.
Open a PDF document
Select "Plug-Ins > Table of Contents > Create TOC from Bookmarks..." in the main menu to open the "Table Of Contents Settings" dialog.
Open the Table Of Contents Settings dialog
Step 2 - Customize TOC Title with Acrobat JavaScript
Click the "Customize..." button located on the "Style" tab of the "Table Of Contents Settings" dialog.
Click Customize button
Check the "Use Acrobat JavaScript scripting to customize TOC title" option and type the JavaScript code into the text box. Click "OK" once done.
Type the JavaScript code into the text box
Using a File Name in the Title
The following sample script assigns the file name (with extension) to the TOC title:
event.value = this.documentFileName;
Using File Name
Using Document Properties
The following code is using values of standard "Title" and "Author" metadata properties to build a custom TOC title. It can produce titles such as: "Reference Manual by John Doe" or, in the example, "Acrobat PDF Consultant by Adobe Developer Support".
event.value = this.title + " by " + this.author;
Using Metadata Properties
Using Bookmarks
The following code is using the title of the first bookmark as a title for the TOC.
event.value = this.bookmarkRoot.children[0].name;
Using Bookmarks
Using Page Count
The following code combines value of the "Title" metadata property with the page count to create a custom title. It can produce titles such as "Reference Manual (100 pages)" or, in the example, "Adobe PDF Consultant (58 pages)":
event.value = this.title + " (" + this.numPages + " pages)";
Using Page Count
Using Multiple Lines
The following code shows how to display TOC title on 3 separate text lines. Use \n to insert a new line. Each metadata property is displayed starting from a new line.
event.value = this.title + "\n" + this.author + "\n" + this.creationDate;
Using Multiple Lines
Changing Text Style
It is possible to change a text color, font name and font size within the title string, but only on the per-line basis. It means only a single color and text font can be used within a single line of text, although text can overflow into multiple lines if the it does not fit into the space available. One or more of different keywords can be used on the same line. The position of the keyword within the line does not matter. It can appear anywhere in the text.
Use {fontsize:XX} to change the font size of the current font to the value of XX, where XX is any integer that represents a valid font size. For example, "{fontsize:20}" - sets the font size to 20 pt.
Use {textcolor:R,G,B} to set a custom text color for the text, where R, G and B are numbers between 0 and 255. These numbers represent intensity of the Red, Green and Blue components of the color. For example, {textcolor:0,0,255} - sets the color of the text to blue.
Use {fontname:Font Name} to change font for the current text line. For example, {fontname: Segoe UI Black} - sets the "Segoe UI Black" as a current font.
The following script creates 3 lines of text for the TOC title. The first line is using a default font style, the second line overrides the text size (sets it to 10) and the third line changes the text color to red.
event.value = "Title\n{fontsize:10}Text size 10\n{textcolor:255,0,0}Red color";
Changing Text Style
Adding Horizontal Divider
The following script draws a horizontal line from left to right margin. Parameters: T - is a line thickness in points (1 inch is 72 points), Y - is a vertical offset of the line from the current text baseline also measured in points. The line is drawn using a current text color.
event.value = "{drawline:T,Y}";
For example, use the following script to draw a line 4 pt thick with vertical offset of 10 points. It will output Table of Contents title with a line draw 10 points below the text baseline.
event.value = "{drawline:4,10}Table of Contents";
Adding Horizontal Divider
The following script creates 2 lines of text and draws a blue divider afer a second line:
event.value = "Table of Contents\nTerms and definitions{drawline:4,10}{textcolor:0,0,255}";
Adding Color Horizontal Divider
Step 3 - Generate Table of Contents
Specify the rest of the settings and click "OK" to generate table of contents.
Generate Table of Contents
Click here for a list of all step-by-step tutorials available.