# How to Add Table of Contents in C#
IronPDF lets you add a table of contents to PDF documents in C# by setting the `TableOfContents` property, which automatically generates hyperlinked navigation from HTML headers (`h1`-`h6`) with optional page numbers.
*as-heading:2(Quickstart: Add Table of Contents to PDF in C#)*
```cs
:title=Generate a PDF with a Table of Contents in one line!
new ChromePdfRenderer { RenderingOptions = { TableOfContents = TableOfContentsTypes.WithPageNumbers, FirstPageNumber = 1 } }
.RenderHtmlFileAsPdf("myDocument.html")
.SaveAs("withToc.pdf");
```
<div class="hsg-featured-snippet">
<h3>Minimal Workflow (5 steps)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronPdf/">Download the C# library for adding a table of contents</a></li>
<li>Prepare the HTML to be converted to PDF</li>
<li>Set the <strong>TableOfContents</strong> property to enable the table of contents</li>
<li>Choose whether to display page numbers or not</li>
<li>Optimize the placement of the table of contents</li>
</ol>
</div>
<br class="clear" />
## What Is a Table of Contents in PDF?
A table of contents (TOC) is a roadmap that helps readers navigate through the PDF document's contents. It typically appears at the beginning and lists the main sections or chapters of the PDF, along with the page numbers where each section begins. This allows readers to quickly find and jump to specific parts of the document, making it easier to access the information they need.
IronPDF provides a feature to create a table of contents with hyperlinks to the `h1`, `h2`, `h3`, `h4`, `h5`, and `h6` elements. The default styling of this table of contents will not conflict with other styles in the HTML content. When you [create new PDFs](https://ironpdf.com/how-to/create-new-pdfs/) using IronPDF, the table of contents feature automatically scans your HTML headers and builds a hierarchical navigation structure that mirrors your document's organization.
The generated table of contents includes clickable links that allow readers to jump directly to any section, making it particularly useful for long documents, reports, and technical documentation. IronPDF's TOC implementation preserves the semantic structure of your HTML while providing professional PDF navigation capabilities.
## How Do I Add a Table of Contents to My PDF?
Use the `TableOfContents` property to enable the creation of a table of contents in the output PDF document. This property can be assigned to one of three `TableOfContentsTypes`, which are described as follows:
- `None`: Do not create a table of contents
- `Basic`: Create a table of contents without page numbers
- `WithPageNumbers`: Create a table of contents WITH page numbers
This feature uses JavaScript to build the table of contents; therefore, the engine must have JavaScript enabled. When converting [HTML files to PDF](https://ironpdf.com/how-to/html-file-to-pdf/), IronPDF's JavaScript engine processes your header tags and generates the appropriate navigation structure. To understand this feature better, download the sample HTML file below:
- <a href="/static-assets/pdf/how-to/table-of-contents/tableOfContent.html" download='tableOfContent.html'>Download the sample HTML file</a>
### What Code Do I Need to Generate the Table of Contents?
```csharp
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure render options
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of content feature
TableOfContents = TableOfContentsTypes.WithPageNumbers,
};
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableOfContent.html");
pdf.SaveAs("tableOfContents.pdf");
```
For more advanced scenarios, you can combine the table of contents with other [rendering options](https://ironpdf.com/how-to/rendering-options/) to create comprehensive PDF documents:
```csharp
using IronPdf;
// Create renderer with multiple options
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of contents with page numbers
TableOfContents = TableOfContentsTypes.WithPageNumbers,
// Add margins for better formatting
MarginTop = 40,
MarginBottom = 40,
// Enable JavaScript for dynamic content
EnableJavaScript = true,
// Set paper orientation
PaperOrientation = PdfPaperOrientation.Portrait,
// Add first page number offset
FirstPageNumber = 1
};
// Convert HTML with multiple header levels
string htmlContent = @"
<h1>Introduction</h1>
<p>Welcome to our comprehensive guide...</p>
<h2>Chapter 1: Getting Started</h2>
<p>Let's begin with the basics...</p>
<h3>1.1 Prerequisites</h3>
<p>Before we start, ensure you have...</p>
<h2>Chapter 2: Advanced Topics</h2>
<p>Now let's explore more complex features...</p>
";
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("document-with-toc.pdf");
```
### What Does the Generated PDF Look Like?
<iframe loading="lazy" src="/static-assets/pdf/how-to/table-of-contents/tableOfContents.pdf#view=75%&page=2" width="100%" height="500px">
</iframe>
The table of contents will be created with hyperlinks to each of the `h1`, `h2`, `h3`, `h4`, `h5`, and `h6`. The hierarchical structure of your headers is preserved, with sub-headers properly indented under their parent sections. You can also [add page numbers](https://ironpdf.com/how-to/page-numbers/) to your PDF for additional navigation support alongside the table of contents.
[[i:(Using the `Merge` method on the document will break the hyperlinks of the table of contents.)]]
When working with [merged or split PDFs](https://ironpdf.com/how-to/merge-or-split-pdfs/), generate the table of contents after all document assembly is complete to ensure accurate page references and functional hyperlinks.
---
## Where Should I Place the Table of Contents in My PDF?
1. Ensure that the HTML document has proper header tags (`h1` up to `h6`).
2. *Optionally* insert a div for where you want the Table of Contents to appear. If the below div is not provided, IronPDF will insert the Table of Contents at the start.
```html
<div id="ironpdf-toc"></div>
```
3. In the render options, choose to render the table of contents either with or without page numbers.
For documents with complex layouts, combine the table of contents with [headers and footers](https://ironpdf.com/how-to/headers-and-footers/) to create a professional document structure. Here's an example of proper HTML structure for optimal TOC generation:
```html
<!DOCTYPE html>
<html>
<head>
<title>My Document</title>
</head>
<body>
<!-- Table of Contents placeholder -->
<div id="ironpdf-toc"></div>
<!-- Page break after TOC -->
<div style="page-break-after: always;"></div>
<!-- Main content starts here -->
<h1>Executive Summary</h1>
<p>This document provides...</p>
<h2>Market Analysis</h2>
<h3>Current Trends</h3>
<p>The market shows...</p>
<h3>Future Projections</h3>
<p>We anticipate...</p>
<h2>Recommendations</h2>
<p>Based on our analysis...</p>
</body>
</html>
```
---
## How Do I Style the Table of Contents?
The Table of Contents can be styled using CSS by targeting the various CSS selectors that define the style of the Table of Contents. When [managing fonts](https://ironpdf.com/how-to/manage-fonts/) in your PDF, the table of contents will inherit your document's font settings by default, but can be customized independently.
In addition, styling modifications can be done using the `CustomCssUrl` property. Begin by downloading a CSS file that contains the original styling for the table of contents below.
- <a href="/static-assets/pdf/how-to/table-of-contents/custom.css" download='custom.css'>Download the custom CSS file</a>
[[w:(Currently, it's not recommended to overwrite the `page-break-before` and `page-break-after` properties when styling the table of contents, as this will break page number calculations. The current implementation expects the Table of Contents to be on separate pages from other document content.)]]
```csharp
using IronPdf;
using System.IO;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure render options
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of content feature
TableOfContents = TableOfContentsTypes.WithPageNumbers,
CustomCssUrl = "./custom.css"
};
// Read HTML text from file
string html = File.ReadAllText("tableOfContent.html");
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("tableOfContents.pdf");
```
When working with [custom paper sizes](https://ironpdf.com/how-to/custom-paper-size/), you may need to adjust the table of contents styling to accommodate different page dimensions and ensure proper text flow and pagination.
### How Do I Style Different Header Levels?
Use the `#ironpdf-toc ul li.h1` selector to apply different styling to the H1 header in the table of contents. Replace `h1` with `h2` up to `h6` to change the styling for each respective header.
```css
#ironpdf-toc ul li.h1 {
font-style: italic;
font-weight: bold;
}
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/table-of-contents/style-headers.webp" alt="Styled table of contents with dotted leaders connecting hierarchical chapters and sections to page numbers" class="img-responsive add-shadow" />
</div>
</div>
### How Do I Change the Font Family?
With both the '`#ironpdf-toc li .title`' and '`#ironpdf-toc li .page`' selectors, it is possible to overwrite the font family of the table of contents. To do this, use the cursive font for the title and utilize the @font-face attribute to use the custom '[Lemon](https://fonts.google.com/specimen/Lemon)' font designed by Eduardo Tunni.
- <a href="/static-assets/pdf/how-to/table-of-contents/Lemon-Regular.ttf" download='Lemon-Regular.ttf'>Download the Lemon font</a>
```css
#ironpdf-toc li .title {
order: 1;
font-family: cursive;
}
@font-face {
font-family: 'lemon';
src: url('Lemon-Regular.ttf')
}
#ironpdf-toc li .page {
order: 3;
font-family: 'lemon', sans-serif;
}
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/table-of-contents/font-family.webp" alt="Table of contents with chapters, sections, and lessons showing dotted leaders and right-aligned page numbers" class="img-responsive add-shadow" />
</div>
</div>
### How Do I Control Indentation?
Indentation can be controlled using the `:root` selector. This value determines the amount of indent for each header level (`h1`, `h2`, ...) in the table of contents. It can be increased as needed, or there can be no indentation with a value of 0.
```css
:root {
--indent-length: 25px;
}
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/table-of-contents/indentation.webp" alt="Table of contents with custom indented chapters, sections, and lessons showing dotted leaders to page numbers" class="img-responsive add-shadow" />
</div>
</div>
### How Do I Remove or Customize the Dot Lines?
To remove the dotted lines between the header title and page number, modify the background-image of the `::after` selector. In the original styling, the second parameter is "currentcolor 1px". Change it to "transparent 1px" to remove the dots. It is important to specify other attributes as well because, in this selector, the new styling will completely override the old styling rather than just adding to it.
```css
#ironpdf-toc li::after {
background-image: radial-gradient(circle, transparent 1px, transparent 1.5px);
background-position: bottom;
background-size: 1ex 4.5px;
background-repeat: space no-repeat;
content: "";
flex-grow: 1;
height: 1em;
order: 2;
}
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/table-of-contents/dot-line.webp" alt="Table of contents with chapters, sections, and lessons showing hierarchical indentation and right-aligned page numbers" class="img-responsive add-shadow" />
</div>
</div>
For more advanced styling options, create custom leader lines using different patterns:
```css
/* Dashed line leader */
#ironpdf-toc li::after {
background-image: linear-gradient(to right, currentcolor 50%, transparent 50%);
background-size: 8px 1px;
background-repeat: repeat-x;
background-position: bottom;
}
/* Solid line leader */
#ironpdf-toc li::after {
border-bottom: 1px solid currentcolor;
background: none;
}
```
Ready to see what else you can do? Check out our tutorial page here: [Convert PDFs](https://ironpdf.com/tutorials/html-to-pdf/)
IronPDF lets you add a table of contents to PDF documents in C# by setting the TableOfContents property, which automatically generates hyperlinked navigation from HTML headers (h1-h6) with optional page numbers.
Set the TableOfContents property to enable the table of contents
Choose whether to display page numbers or not
Optimize the placement of the table of contents
What Is a Table of Contents in PDF?
A table of contents (TOC) is a roadmap that helps readers navigate through the PDF document's contents. It typically appears at the beginning and lists the main sections or chapters of the PDF, along with the page numbers where each section begins. This allows readers to quickly find and jump to specific parts of the document, making it easier to access the information they need.
IronPDF provides a feature to create a table of contents with hyperlinks to the h1, h2, h3, h4, h5, and h6 elements. The default styling of this table of contents will not conflict with other styles in the HTML content. When you create new PDFs using IronPDF, the table of contents feature automatically scans your HTML headers and builds a hierarchical navigation structure that mirrors your document's organization.
The generated table of contents includes clickable links that allow readers to jump directly to any section, making it particularly useful for long documents, reports, and technical documentation. IronPDF's TOC implementation preserves the semantic structure of your HTML while providing professional PDF navigation capabilities.
How Do I Add a Table of Contents to My PDF?
Use the TableOfContents property to enable the creation of a table of contents in the output PDF document. This property can be assigned to one of three TableOfContentsTypes, which are described as follows:
None: Do not create a table of contents
Basic: Create a table of contents without page numbers
WithPageNumbers: Create a table of contents WITH page numbers
This feature uses JavaScript to build the table of contents; therefore, the engine must have JavaScript enabled. When converting HTML files to PDF, IronPDF's JavaScript engine processes your header tags and generates the appropriate navigation structure. To understand this feature better, download the sample HTML file below:
What Code Do I Need to Generate the Table of Contents?
using IronPdf;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Configure render optionsrenderer.RenderingOptions = new ChromePdfRenderOptions{ // Enable table of content featureTableOfContents = TableOfContentsTypes.WithPageNumbers,};PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableOfContent.html");pdf.SaveAs("tableOfContents.pdf");
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure render options
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of content feature
TableOfContents = TableOfContentsTypes.WithPageNumbers,
};
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableOfContent.html");
pdf.SaveAs("tableOfContents.pdf");
ImportsIronPdf' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Configure render optionsrenderer.RenderingOptions = New ChromePdfRenderOptionsWith {.TableOfContents = TableOfContentsTypes.WithPageNumbers}Dim pdf AsPdfDocument = renderer.RenderHtmlFileAsPdf("tableOfContent.html")pdf.SaveAs("tableOfContents.pdf")
Imports IronPdf
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Configure render options
renderer.RenderingOptions = New ChromePdfRenderOptions With {.TableOfContents = TableOfContentsTypes.WithPageNumbers}
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("tableOfContent.html")
pdf.SaveAs("tableOfContents.pdf")
For more advanced scenarios, you can combine the table of contents with other rendering options to create comprehensive PDF documents:
using IronPdf;// Create renderer with multiple optionsChromePdfRenderer renderer = new ChromePdfRenderer();renderer.RenderingOptions = new ChromePdfRenderOptions{ // Enable table of contents with page numbersTableOfContents = TableOfContentsTypes.WithPageNumbers, // Add margins for better formattingMarginTop = 40,MarginBottom = 40, // Enable JavaScript for dynamic contentEnableJavaScript = true, // Set paper orientationPaperOrientation = PdfPaperOrientation.Portrait, // Add first page number offsetFirstPageNumber = 1}; // Convert HTML with multiple header levelsstring htmlContent = @"<h1>Introduction</h1><p>Welcome to our comprehensive guide...</p><h2>Chapter 1: Getting Started</h2><p>Let's begin with the basics...</p><h3>1.1 Prerequisites</h3><p>Before we start, ensure you have...</p><h2>Chapter 2: Advanced Topics</h2><p>Now let's explore more complex features...</p>";PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);pdf.SaveAs("document-with-toc.pdf");
using IronPdf;
// Create renderer with multiple options
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of contents with page numbers
TableOfContents = TableOfContentsTypes.WithPageNumbers,
// Add margins for better formatting
MarginTop = 40,
MarginBottom = 40,
// Enable JavaScript for dynamic content
EnableJavaScript = true,
// Set paper orientation
PaperOrientation = PdfPaperOrientation.Portrait,
// Add first page number offset
FirstPageNumber = 1
};
// Convert HTML with multiple header levels
string htmlContent = @"
<h1>Introduction</h1>
<p>Welcome to our comprehensive guide...</p>
<h2>Chapter 1: Getting Started</h2>
<p>Let's begin with the basics...</p>
<h3>1.1 Prerequisites</h3>
<p>Before we start, ensure you have...</p>
<h2>Chapter 2: Advanced Topics</h2>
<p>Now let's explore more complex features...</p>
";
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("document-with-toc.pdf");
ImportsIronPdf' Create renderer with multiple optionsDim renderer As New ChromePdfRenderer()renderer.RenderingOptions = New ChromePdfRenderOptionsWith { ' Enable table of contents with page numbers .TableOfContents = TableOfContentsTypes.WithPageNumbers, ' Add margins for better formatting .MarginTop = 40, .MarginBottom = 40, ' Enable JavaScript for dynamic content .EnableJavaScript = True, ' Set paper orientation .PaperOrientation = PdfPaperOrientation.Portrait, ' Add first page number offset .FirstPageNumber = 1}' Convert HTML with multiple header levelsDim htmlContent AsString = "<h1>Introduction</h1><p>Welcome to our comprehensive guide...</p><h2>Chapter 1: Getting Started</h2><p>Let's begin with the basics...</p><h3>1.1 Prerequisites</h3><p>Before we start, ensure you have...</p><h2>Chapter 2: Advanced Topics</h2><p>Now let's explore more complex features...</p>"Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(htmlContent)pdf.SaveAs("document-with-toc.pdf")
Imports IronPdf
' Create renderer with multiple options
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions = New ChromePdfRenderOptions With {
' Enable table of contents with page numbers
.TableOfContents = TableOfContentsTypes.WithPageNumbers,
' Add margins for better formatting
.MarginTop = 40,
.MarginBottom = 40,
' Enable JavaScript for dynamic content
.EnableJavaScript = True,
' Set paper orientation
.PaperOrientation = PdfPaperOrientation.Portrait,
' Add first page number offset
.FirstPageNumber = 1
}
' Convert HTML with multiple header levels
Dim htmlContent As String = "
<h1>Introduction</h1>
<p>Welcome to our comprehensive guide...</p>
<h2>Chapter 1: Getting Started</h2>
<p>Let's begin with the basics...</p>
<h3>1.1 Prerequisites</h3>
<p>Before we start, ensure you have...</p>
<h2>Chapter 2: Advanced Topics</h2>
<p>Now let's explore more complex features...</p>
"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("document-with-toc.pdf")
What Does the Generated PDF Look Like?
The table of contents will be created with hyperlinks to each of the h1, h2, h3, h4, h5, and h6. The hierarchical structure of your headers is preserved, with sub-headers properly indented under their parent sections. You can also add page numbers to your PDF for additional navigation support alongside the table of contents.
Please note: Using the Merge method on the document will break the hyperlinks of the table of contents.
When working with merged or split PDFs, generate the table of contents after all document assembly is complete to ensure accurate page references and functional hyperlinks.
Where Should I Place the Table of Contents in My PDF?
Ensure that the HTML document has proper header tags (h1 up to h6).
Optionally insert a div for where you want the Table of Contents to appear. If the below div is not provided, IronPDF will insert the Table of Contents at the start.
<div id="ironpdf-toc"></div>
<div id="ironpdf-toc"></div>
HTML
In the render options, choose to render the table of contents either with or without page numbers.
For documents with complex layouts, combine the table of contents with headers and footers to create a professional document structure. Here's an example of proper HTML structure for optimal TOC generation:
<!DOCTYPE html><html><head> <title>My Document</title></head><body> <!-- Table of Contents placeholder --> <div id="ironpdf-toc"></div> <!-- Page break after TOC --> <div style="page-break-after: always;"></div> <!-- Main content starts here --> <h1>Executive Summary</h1> <p>This document provides...</p> <h2>Market Analysis</h2> <h3>Current Trends</h3> <p>The market shows...</p> <h3>Future Projections</h3> <p>We anticipate...</p> <h2>Recommendations</h2> <p>Based on our analysis...</p></body></html>
My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.
IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.
The Table of Contents can be styled using CSS by targeting the various CSS selectors that define the style of the Table of Contents. When managing fonts in your PDF, the table of contents will inherit your document's font settings by default, but can be customized independently.
In addition, styling modifications can be done using the CustomCssUrl property. Begin by downloading a CSS file that contains the original styling for the table of contents below.
Warning: Currently, it's not recommended to overwrite the page-break-before and page-break-after properties when styling the table of contents, as this will break page number calculations. The current implementation expects the Table of Contents to be on separate pages from other document content.
using IronPdf;using System.IO;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Configure render optionsrenderer.RenderingOptions = new ChromePdfRenderOptions{ // Enable table of content featureTableOfContents = TableOfContentsTypes.WithPageNumbers,CustomCssUrl = "./custom.css"};// Read HTML text from filestring html = File.ReadAllText("tableOfContent.html");PdfDocument pdf = renderer.RenderHtmlAsPdf(html);pdf.SaveAs("tableOfContents.pdf");
using IronPdf;
using System.IO;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure render options
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of content feature
TableOfContents = TableOfContentsTypes.WithPageNumbers,
CustomCssUrl = "./custom.css"
};
// Read HTML text from file
string html = File.ReadAllText("tableOfContent.html");
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("tableOfContents.pdf");
ImportsIronPdfImportsSystem.IO' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Configure render optionsrenderer.RenderingOptions = New ChromePdfRenderOptionsWith { .TableOfContents = TableOfContentsTypes.WithPageNumbers, .CustomCssUrl = "./custom.css"}' Read HTML text from fileDim html AsString = File.ReadAllText("tableOfContent.html")Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)pdf.SaveAs("tableOfContents.pdf")
Imports IronPdf
Imports System.IO
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Configure render options
renderer.RenderingOptions = New ChromePdfRenderOptions With {
.TableOfContents = TableOfContentsTypes.WithPageNumbers,
.CustomCssUrl = "./custom.css"
}
' Read HTML text from file
Dim html As String = File.ReadAllText("tableOfContent.html")
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("tableOfContents.pdf")
When working with custom paper sizes, you may need to adjust the table of contents styling to accommodate different page dimensions and ensure proper text flow and pagination.
How Do I Style Different Header Levels?
Use the #ironpdf-toc ul li.h1 selector to apply different styling to the H1 header in the table of contents. Replace h1 with h2 up to h6 to change the styling for each respective header.
#ironpdf-toc ul li.h1 { font-style: italic; font-weight: bold;}
#ironpdf-toc ul li.h1 {
font-style: italic;
font-weight: bold;
}
Text
How Do I Change the Font Family?
With both the '#ironpdf-toc li .title' and '#ironpdf-toc li .page' selectors, it is possible to overwrite the font family of the table of contents. To do this, use the cursive font for the title and utilize the @font-face attribute to use the custom 'Lemon' font designed by Eduardo Tunni.
Indentation can be controlled using the :root selector. This value determines the amount of indent for each header level (h1, h2, ...) in the table of contents. It can be increased as needed, or there can be no indentation with a value of 0.
:root { --indent-length: 25px;}
:root {
--indent-length: 25px;
}
Text
How Do I Remove or Customize the Dot Lines?
To remove the dotted lines between the header title and page number, modify the background-image of the ::after selector. In the original styling, the second parameter is "currentcolor 1px". Change it to "transparent 1px" to remove the dots. It is important to specify other attributes as well because, in this selector, the new styling will completely override the old styling rather than just adding to it.
Ready to see what else you can do? Check out our tutorial page here: Convert PDFs
Frequently Asked Questions
What is the advantage of using IronPDF to add a Table of Contents in C#?
IronPDF simplifies the process of adding a table of contents by automating hyperlinked navigation from HTML headers. This feature ensures easy navigation through PDF documents using a structured TOC with page numbers.
How can I create a table of contents with page numbers using IronPDF?
You can create a table of contents with page numbers by setting the `TableOfContents` property to `TableOfContentsTypes.WithPageNumbers` in IronPDF's `ChromePdfRenderOptions` during PDF generation.
Can IronPDF automatically generate a table of contents from HTML headers?
Yes, IronPDF can automatically generate a table of contents from HTML header tags (h1-h6), preserving the hierarchy and allowing easy navigation across document sections.
How do I customize the styling of a Table of Contents generated with IronPDF?
The styling of a Table of Contents can be customized using CSS. You can modify the font, indentation, and leader lines by targeting CSS selectors used by IronPDF's TOC feature.
What are the rendering options available for the Table of Contents feature in IronPDF?
IronPDF offers three rendering options for the table of contents: `None`, `Basic` (without page numbers), and `WithPageNumbers`. These settings can be configured in the rendering options when generating PDFs.
Is it possible to use custom CSS to style the table of contents when using IronPDF?
Yes, you can use custom CSS to style the table of contents in IronPDF by setting the `CustomCssUrl` property in the `ChromePdfRenderOptions` during PDF creation.
Can I specify where the table of contents should appear in my PDF using IronPDF?
Yes, you can specify a placeholder in your HTML using a div with the id `ironpdf-toc`. If not specified, IronPDF will automatically place the table of contents at the start of the document.
Does IronPDF support dynamic content like JavaScript when generating PDFs?
Yes, IronPDF supports dynamic content and can execute JavaScript during the conversion process, enhancing the interactivity of the generated PDF.
How can I download a sample HTML file to see how Table of Contents is structured?
You can download a sample HTML file directly from the IronPDF guide to understand how the table of contents is structured before converting it to a PDF.
What should I be cautious of when styling the table of contents in IronPDF?
When styling the table of contents, avoid modifying `page-break-before` and `page-break-after` properties within the TOC styling, as they may disrupt page number calculations in the PDF.
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.