Click or drag to resize

TableOfContents Class

A table of contents with page numbers and links, inserted in a document with InsertTableOfContents(TableOfContents, Int32).
Inheritance Hierarchy
SystemObject
  ExpertPdf.PdfCreatorTableOfContents

Namespace: ExpertPdf.PdfCreator
Assembly: epdfcreator (in epdfcreator.dll) Version: 22.0.0
Syntax
public class TableOfContents

The TableOfContents type exposes the following members.

Constructors
 NameDescription
Public methodTableOfContents Creates an empty table of contents.
Top
Properties
 NameDescription
Public propertyDotLeaders Gets or sets whether a dotted leader joins the text of each entry to its page number. The default is True.
Public propertyEntries Gets the entries, in the order they are listed.
Public propertyEntryColor Gets or sets the color of the entries. The default is black.
Public propertyEntryFont Gets or sets the font of the entries. When it is null (the default), Arial 11pt is embedded in the document.
Public propertyEntrySpacing Gets or sets the space in points between two entries. The default is 4.
Public propertyLevelIndent Gets or sets how far, in points, each level is indented from the one above it. The default is 18.
Public propertyTitle Gets or sets the title written above the entries. The default is "Contents"; null or empty writes no title.
Public propertyTitleColor Gets or sets the color of the title. The default is black.
Public propertyTitleFont Gets or sets the font of the title. When it is null (the default), Arial Bold 18pt is embedded in the document.
Top
Methods
 NameDescription
Public methodAddEntries Adds an entry for each element of an element mapping result, in the order the elements appear in the document.
Public methodAddEntry Adds an entry that points to a place in the document.
Public methodClear Removes all the entries.
Top
Remarks

Add the entries - the headings an HTML element mapped (AddEntries(Document, HtmlElementMappingsCollection)) or entries of your own (AddEntry(String, Int32, PdfPage, Single)) - after the content is added to the document, then insert the table of contents where it goes. Each entry shows its text indented by its level, a dotted leader and the number of the page it points to, and is a link to that place.

In a tagged document the table of contents is tagged as a TOC element, with the title as its Caption and one TOCI item per entry.

Example
Document document = new Document();
PdfPage page = document.AddPage();
HtmlToPdfElement html = new HtmlToPdfElement("https://www.html-to-pdf.info");
html.RenderingEngine = RenderingEngine.Chromium;
html.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { "h1", "h2" };
page.AddElement(html);

TableOfContents toc = new TableOfContents();
toc.AddEntries(document, html.HtmlElementsMappingOptions.HtmlElementsMappingResult);
document.InsertTableOfContents(toc, 0);
document.Save("toc.pdf");
See Also