Document TemplateTable Of Contents And Index

This page demonstrates inclusion of table of contents and index, as well as multiple sections.

Sample Data 

For the sample data, the first five records of Northwinds Customers table.

{
    "static": [
        {
            "CustomerID": "ALFKI",
            "CompanyName": "Alfreds Futterkiste",
            "ContactName": "Maria Anders",
            "ContactTitle": "Sales Representative",
            "Address": "Obere Str. 57",
            "City": "Berlin",
            "Region": null,
            "PostalCode": "12209",
            "Country": "Germany",
            "Phone": "030-0074321",
            "Fax": "030-0076545"
        },
        {
            "CustomerID": "ANATR",
            "CompanyName": "Ana Trujillo Emparedados y helados",
            "ContactName": "Ana Trujillo",
            "ContactTitle": "Owner",
            "Address": "Avda. de la Constitución 2222",
            "City": "México D.F.",
            "Region": null,
            "PostalCode": "05021",
            "Country": "Mexico",
            "Phone": "(5) 555-4729",
            "Fax": "(5) 555-3745"
        },
        {
            "CustomerID": "ANTON",
            "CompanyName": "Antonio Moreno Taquería",
            "ContactName": "Antonio Moreno",
            "ContactTitle": "Owner",
            "Address": "Mataderos  2312",
            "City": "México D.F.",
            "Region": null,
            "PostalCode": "05023",
            "Country": "Mexico",
            "Phone": "(5) 555-3932",
            "Fax": null
        },
        {
            "CustomerID": "AROUT",
            "CompanyName": "Around the Horn",
            "ContactName": "Thomas Hardy",
            "ContactTitle": "Sales Representative",
            "Address": "120 Hanover Sq.",
            "City": "London",
            "Region": null,
            "PostalCode": "WA1 1DP",
            "Country": "UK",
            "Phone": "(171) 555-7788",
            "Fax": "(171) 555-6750"
        },
        {
            "CustomerID": "BERGS",
            "CompanyName": "Berglunds snabbköp",
            "ContactName": "Christina Berglund",
            "ContactTitle": "Order Administrator",
            "Address": "Berguvsvägen  8",
            "City": "Luleå",
            "Region": null,
            "PostalCode": "S-958 22",
            "Country": "Sweden",
            "Phone": "0921-12 34 65",
            "Fax": "0921-12 34 67"
        }
    ]
}

Document Template 

{
    "content": [
        {
            "section": {
                "header": {
                    "primary": {
                        "textformat": {
                            "justification": "Center"
                        },
                        "text": "- Table of Contents -"
                    }
                }
            },
            "sectionname": "toc"
        },
        {
            "section": {
                "header": {
                    "primary": {
                        "text": "Page ({{pageno}})"
                    }
                }
            },
            "block": {
                "source": "*root",
                "startnew": "Page",
                "content": [
                    {
                        "text": "Customer ID"
                    },
                    {
                        "field": "CustomerID"
                    },
                    {
                        "text": "\r\nCompany Name:"
                    },
                    {
                        "field": "CompanyName",
                        "bookmark": {
                            "toc": true
                        }
                    },
                    {
                        "text": "\r\nContact Name:"
                    },
                    {
                        "field": "ContactName"
                    },
                    {
                        "text": "\r\nContact Title:"
                    },
                    {
                        "field": "ContactTitle"
                    },
                    {
                        "text": "\r\nAddress:"
                    },
                    {
                        "field": "Address"
                    },
                    {
                        "text": "\r\nCity:"
                    },
                    {
                        "field": "City"
                    },
                    {
                        "indexfield": "City"
                    },
                    {
                        "text": "\r\nRegion:"
                    },
                    {
                        "field": "Region"
                    },
                    {
                        "text": "\r\nPostal Code:"
                    },
                    {
                        "field": "PostalCode"
                    },
                    {
                        "text": "\r\nCountry:"
                    },
                    {
                        "field": "Country"
                    },
                    {
                        "text": "\r\nPhone:"
                    },
                    {
                        "field": "Phone"
                    },
                    {
                        "text": "\r\nFax:"
                    },
                    {
                        "field": "Fax"
                    }
                ]
            }
        },
        {
            "section": {
                "header": {
                    "primary": {
                        "textformat": {
                            "justification": "Center"
                        },
                        "text": "- Index -"
                    }
                }
            },
            "sectionname": "index"
        }
    ]
}

Adding Placeholders for Table of Contents, Index and adding entries. 

Unlike prior examples, The Top level contents does not iterate over the top level array, the *root is the second content block between the table of contents page, denoted by sectionname 'toc', and the index denoted by sectionname 'index'.

The items that appear in the table of contents are bookmarks with the "toc" property set to true, not shown in this example, table of contents entries may also index an indentation level.

The index entries are created using either an "indexfield" or "indextemplate".

In this example, the table of contents and index sections have thier own 'section' properties so that they can have custom page headers.

Table of contents Page
Index Page

Table Of Contents Indent 

{
        "field": "CompanyName",
        "bookmark": {
            "toc": true
        }
    },
    ....
    {
        "field": "ContactName",
        "bookmark": {
            "toc": true,
            "tocindent": "1in"
        }
    },
    ...
    {
        "field": "Address",
        "bookmark": {
            "toc": true,
            "tocindent": "1in"
        }
    },

Entries in the table of contents can be indented using the "tocindent" property.

The above changes to add ContactName and Address to the TOC with a 1 inch indent result in the table contents below.

This example is contrived to demonstrate the styling, normally this would be used to show different levels of grouping.

Table of contents Page

Index using indextemplate 

....
    {
        "indextemplate": [
            {
                "field": "City"
            },
            ",",
            {
                "field": "Country"
            }
        ]
    }

Index entries can be more complex that merely a field, the indextemplate allows multiple fields to be composited into an entry.

Table of contents Page