Skip to main content

Update Table of Contents - TOC Management API

PDF4me Update Table of Contents enables you to update or create Table of Contents in Word documents with comprehensive formatting options and professional styling capabilities. This API service processes Word files and generates TOCs with automatic detection of existing TOC fields, customizable heading levels, hyperlink support, tab leader control, text case options, and culture localization. The API receives Word document content through REST API calls, utilizing Base64 encoding for secure transmission. With full control over TOC appearance and functionality, this solution is ideal for document navigation, professional formatting, and automated TOC generation workflows.

Authenticating Your API Request

To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.

Key Features

  • Automatic TOC Detection: Finds and updates existing TOC fields or creates new ones
  • Customizable Heading Levels: Control which heading levels to include (1-6)
  • Hyperlink Support: Enable or disable clickable links in the TOC
  • Tab Leader Control: Show or hide dots between text and page numbers
  • Text Case Options: Use uppercase or preserve original case
  • Culture Localization: Support for different languages and regions
  • Professional Formatting: Automatic application of professional TOC styling
  • Page Number Integration: Automatic page number calculation and updates

REST API Endpoint

The PDF4me REST API uses standard HTTP methods to interact with resources. All table of contents update operations are performed through a single endpoint:

  • Method: POST
  • Endpoint: office/ApiV2Word/UpdateTableOfContents

REST API Parameters

Complete list of parameters for the Update Table of Contents REST API. Parameters are organized by category for better understanding and implementation.

Important: Parameters marked with an asterisk (*) are required. Advanced parameters provide fine-grained control over TOC formatting and appearance.

Required Parameters

ParameterTypeDescriptionExample
document*ObjectDocument reference. Must contain Name (string) — Word file name with .docx extension{ "Name": "document.docx" }
docContent*Base64Word document content encoded in Base64. TOC is generated from this document's headings. Must be valid Word document (.docx, .doc formats)UEsDBBQABgAIAAAA...

Optional Parameters

ParameterTypeDescriptionExample
headingLevelsStringHeading levels to include in TOC. Range format: "1-3" (includes heading levels 1, 2, and 3). Single level: "1". Multiple ranges: "1-2,4-6". Default: "1-3". Maps to Word's built-in heading styles. Scans document for existing TOC fields. Creates new TOC at document start if none exists"1-3"
useHyperlinksBooleanInclude hyperlinks in Table of Contents. true = TOC entries are clickable links (default), false = plain texttrue
hideTabLeaderBooleanHide tab leader dots. true = No dots between text and page numbers (default), false = Dots between text and page numberstrue
useUppercaseBooleanUse uppercase for TOC entries. true = TOC entries in uppercase (default), false = original casetrue
cultureNameStringCulture code for document processing (e.g., "en-US", "de-DE", "fr-FR"). Default: null. Affects document language and formattingen-US

TOC Generation Behavior

  • Existing TOC Detection: Scans document for existing TOC fields (FieldType.FieldTOC) and updates them
  • New TOC Creation: If no TOC exists, creates new TOC at document start
  • Heading Level Mapping: Maps to Word's built-in heading styles (Heading 1, Heading 2, etc.)
  • Field Updates: Updates fields multiple times for accuracy
  • Page Layout: Calls UpdateFields() and UpdatePageLayout() in sequence

Output

The PDF4me Update Table of Contents REST API returns different responses based on the processing mode. The API returns the Word document as a Base64-encoded string in JSON format, not as binary data.

Synchronous Processing (Default)

The API processes the request and returns:

Status Code: 200 OK

Content-Type: application/json

Response Body:

{
"document": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"fileName": "document.docx",
"success": true,
"errorMessage": null
}

Response Fields:

  • document (string): The Word document with updated table of contents, encoded as Base64 string
  • fileName (string): The output Word file name
  • success (boolean): Indicates whether the request succeeded
  • errorMessage (string or null): Error details when success is false

How to Use:

  1. Extract the document field from the JSON response (Base64)
  2. Decode the Base64 string to get the binary Word document data
  3. Save or process the Word file as needed

Example (JavaScript):

const response = await fetch(url, options);
const data = await response.json();
const wordBytes = atob(data.document); // Decode Base64
// Save or process wordBytes

Request Example

Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY

Note:

  • Get your API key from the PDF4me Dashboard
  • The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
  • Example: If your API key is abc123, encode it to Base64 and use Authorization: Basic YWJjMTIz

Payload

Basic Example (Default Settings):

{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC..."
}

Advanced Example (With All Options):

{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"headingLevels": "1-4",
"useHyperlinks": true,
"hideTabLeader": false,
"useUppercase": false,
"cultureName": "en-US"
}

Academic Paper Example:

{
"document": { "Name": "research-paper.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"headingLevels": "1-3",
"useHyperlinks": true,
"hideTabLeader": true,
"useUppercase": true
}

Code Samples

The PDF4me Update Table of Contents REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:

C# (CSharp) Sample

Complete C# implementation for updating table of contents in Word documents:

Industry Use Cases & Applications

Legal & Professional Services Use Cases

  • Contract Navigation: Create detailed TOC for complex contracts
  • Legal Briefs: Generate navigable structure for court documents
  • Compliance Manuals: Index regulatory requirements and procedures
  • Case Documentation: Organize evidence and legal arguments

Get Help