Create table of contents in PDF documents

With the release of XFINIUM.PDF 6.2 the table of contents can be generated automatically for flow PDF documents.

The table of contents is generated with the help of a new flow content class: PdfFlowHeadingContent. Heading content is similar to text content but it allows to create a hierarchy based on its Level property. 8 levels (1 to 8) of heading content are supported.
The heading level is used to generate the parent-child bookmarks in document outline and to generate the heading numbers, if required.

Adding heading content is done like this:

The table of contents is generated from all the heading objects included in the document. It should be generated at the end after the entire document content has been created.

The PdfFlowContent.GenerateTableOfContents() method generates the table of contents in the document. The method can accept a PdfFlowDocumentTOCSettings object as parameter for customizing the table of contents. The properties of the PdfFlowDocumentTOCSettings object control how the table of contents is generated.

The code above is taken from the TableOfContents sample included in the XFINIUM.PDF install kits.
After running the sample the table of contents is generated like in the screenshot below.

Table of contents
Table of contents

On the left the table of contents as document outline and in the center the page that displays the table of contents. The entries in the table of contents page are clickable links that take the reader to the corresponding section in the document.

4 thoughts on “Create table of contents in PDF documents”

  1. Hi, i’m evaluating Xfinium, and I just want to know how to display a pdf? I can’t find any info on how to show a pdf in my app, using xfinium. Can you please point me to a resource that explains how to do that?

    1. PDF viewer controls are under development and they will be available later this year. For the moment a PDF file can be displayed if it is rendered as image and the image is displayed. The PDFToImage sample shows this functionality.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.