# Add Table of Contents to PDF: web app and CLI

## What it does
Adds a page that lists the document’s headings or bookmarks and creates links to the corresponding pages. Optionally creates PDF bookmarks and lets you set the TOC title and starting page number.

## Inputs and limits
* Input: a single PDF file (subject to the size limits of the Documentize service).
* The PDF must contain detectable headings or bookmarks; scanned PDFs need OCR before TOC generation.
* Optional parameters: TOC title, starting page number, and whether to generate PDF bookmarks.

## Web app
The web page asks you to upload a PDF file. You can optionally enter a custom TOC title, choose a starting page number, and enable the “Generate bookmarks” option. After upload, the service creates a searchable TOC and returns the processed PDF.

## Command line (CLI)
The CLI plugin processes the PDF from a task‑specific input folder and writes the result to the matching output folder. You must provide a task ID and can set the TOC title with `--title`. Example usage: `dotnet Documentize.AddToc.dll --task-id job1 --title My TOC`. The plugin creates a TOC page titled **My TOC** and writes the processed PDF to the output folder.

```bash
# Linux / macOS (needs the .NET 10 runtime and documentize.lic next to the DLL)
export PLUGIN_INPUT_DIR=./work/input
export PLUGIN_OUTPUT_DIR=./work/output
mkdir -p "$PLUGIN_INPUT_DIR/job1"
cp sample.pdf "$PLUGIN_INPUT_DIR/job1/"
dotnet Documentize.AddToc.dll --task-id job1 --title "My TOC"
ls "$PLUGIN_OUTPUT_DIR/job1"
```

```powershell
# Windows PowerShell
$env:PLUGIN_INPUT_DIR  = "$PWD\work\input"
$env:PLUGIN_OUTPUT_DIR = "$PWD\work\output"
New-Item -ItemType Directory -Force "$env:PLUGIN_INPUT_DIR\job1" | Out-Null
Copy-Item sample.pdf "$env:PLUGIN_INPUT_DIR\job1\"
dotnet Documentize.AddToc.dll --task-id job1 --title "My TOC"
Get-ChildItem "$env:PLUGIN_OUTPUT_DIR\job1"
```

## Verified

Every code sample on this page was run on 2026-11-03 and its result was checked:

- Add TOC via CLI (CLI plugin): passed in 11 s
