Skip to main content

How do I create a Table of Contents in Lasernet? - Knowledgebase / Lasernet / Lasernet FAQs - Formpipe Support Portal

How do I create a Table of Contents in Lasernet?

Authors list

A Table of Contents (TOC) is a way of displaying the content of a generated document, especially if there is a diversity of content or it is a large document.

The TOC is ideally created at the end of the form, once all of the requisite pages are in place. This way, Lasernet can get an accurate view of what sheets and pages will form the TOC.

The contents page is then combined with the rest of the document - after the form engine - to allow it to appear as the first page in the document (as expected). The following example has been created using multiple sheets to highlight how the TOC is able to adapt to the input data. The method in the example can be used in a range of different situations to achieve the same result. To create a TOC with Lasernet, follow the procedure below:

Lasernet setup - setting up the form

1. Create a new form in Lasernet Developer to generate a document that contains a TOC (this process can also be applied to an existing document).

2. Each section of the document must have its own sheet. To add a new sheet, right-click Sheet1 and click Add or Duplicate from the menu that opens.

3. A final sheet is then needed for the TOC.


Do not forget to create a form criteria so that only data for the TOC is matched to the form.

The last sheet must be the TOC, as Lasernet needs to populate all of the metadata about the other sheets (Titles & pages) which can then be passed through to the TOC sheet.

Sheet Combining

You can combine sheets at the form level using Sheet Combining (without needing a Combiner on a PDF Engine or Printer). It also allows for page numbering to continue from sheet to sheet. When enabled, it will combine the current sheet with the next sheet, chaining all active sheets into a single file.

In this example, every sheet except the TOC and the sheet previous to it needs Sheet Combining to be enabled. This is so that Sheet 1 is tied to Sheet 2, Sheet 2 is then tied to Sheet 3. If combining were enabled on Sheet 3, then the TOC sheet would be tied to Sheet 3, putting it at the end of the document.

1. From the first sheet, double-click each individual sheet tab or right-click on the tab and select Sheet Options to bring up the Sheet Options menu.

2. Navigate to the Combining tab within the Sheet Options menu and select Sheet Order and Page Numbering tab.

3. Select the Combining check box.


After turning on Combining, it is possible to see that the sheets are chained together because the destination tab for the following sheet will be disabled, as it takes the settings from the first sheet in the chain. For example, if the chain started at Sheet 1, it would not be possible to set the destination for Sheet 2. As all the intervening sheets are being combined except the TOC sheet, only the destination for the first the TOC sheet need to be set.

This can be set up in two ways:

Sheet level

1. Double click the sheets to bring up the properties.

2. Navigate to the destination tab and add the destination for sending.

Both the first sheet and the TOC sheet must have the same destination.


Module level

A destination can be set on the Form Engine which will send all of the output onwards.

1. When in the modules, click and drag from the Form engine to its destination. This will draw an arrow between the items to show their relationship.

2. Double click the form engine and navigate to the Destinations tab and click Add, and then define the required destination. Also, activate Virtual to illustrate that the form engine will send the job to the PDF engine.

The module that is set as the destination must also have Combining turned on, in order to bring the document and the TOC sheet together.

3. From the main Lasernet view, open the module properties that the form is being sent to and turn on Combining in the Combining tab.


To create the Table of Contents, data must be stored in masterJobInfos (these carry the data across sheets) to define the headings for the TOC and the pages. These are then called by scripts to create the information needed on the TOC sheet.

Scripting is done in the Lasernet Form Designer and the quickest way to achieve it is to add a new text box using the Text tool.

1. Click the Position button and ensure that Last and Single are selected.

2. Click the Objects button to change the Object type from ‘Fixed text’ to ‘Script’, and then copy the script over from the relevant sections.

For versions later than Lasernet 9 you will need to select the Output tab and ensure that Last and Single are selected in the Absolute tab. In the Input tab, use the drop-down box to change the Type of insert text to Script and copy the script over from the relevant sections.

Page count (First sheet only)

In the text box where the script is to be located, the following lines of code need to be added to the first sheet, the last sheet and the single pages only.

The double forward slash (//) designates a comment. We recommend that these are also copied across so that anyone following the script can easily understand what the code is doing.

Using masterJob to set the JobInfo makes the information accessible to all the other sheets in the job. If masterJob was removed, the TOC sheet would no longer be able to reference the JobInfo needed.


//Creates a global variable that states the first sheet is page 1 in the document.

masterJob.setJobInfo("Sheet1PageStart", 1);

//Defines how many pages are in this sheet. This will later be added onto in other sheets.

masterJob.setJobInfo("Sheet1PageCount", job.getJobInfo("CurrentPage"), true);

Sheet1PageStart: designates what page the section starts on, in the document. As this is for the first sheet only, input ‘1’ as the page value.

Sheet1PageCount: works by using the currentPage JobInfo to calculate how many pages this section or sheet contains. By putting this script on the Last and Single pages it is possible to keep count, even with varying data input.

All other sheets

For all the sheets except the first and TOC sheets, the following script needs to be added to the text box as per the method above.

Again, it must only be placed on the Last and Single pages of the sheet. You must also change the JobInfo names to be relevant for the sheet you are working on.


//Sets a JobInfo which adds the previous sheets page count to the overall count

masterJob.setJobInfo("Sheet2PageStart", parseInt(masterJob.getJobInfo("Sheet1PageStart")) + parseInt(masterJob.getJobInfo("Sheet1PageCount")));

//Defines how many pages are in this sheet. This will be added to later, in other sheets.

masterJob.setJobInfo("Sheet2PageCount", job.getJobInfo("CurrentPage"), true);

Sheet2PageStart: takes the previous sheet start value and the number of pages in the section to calculate the section it starts on.

Sheet2PageCount: works as the previous section to calculate how many pages are created for the section.

Table of Contents (TOC) sheet

The following image is an example output of a TOC sheet. The static text has been created to work with scripts that pull the sheet start number for the relevant sheet from the JobInfos.

Using the following code and placing it in the text boxes, allows Lasernet to pull the value for the JobInfo to display. Ensure that you use a relevant JobInfo name for the sheet that is to be displayed.

To display the page number where the section starts use


And to display how many pages are in a section use:


Placing the Table of Contents as the first page

Currently, the TOC is positioned at the end of the generated document. To get the TOC to appear at the start of the sheet, another JobInfo needs to be added to all of the previous scripts. This JobInfo will then be used to determine the order in which the documents are combined in the module the sheets are being sent to. Follow these steps:

1. Use the following line of code to set this on all sheets except the TOC sheet:

job.setJobInfo("ToCFirst", 1);

2. On the TOC sheet, the value must be set to 0. Use the following line of code on the TOC sheet only:

job.setJobInfo("ToCFirst", 0);

In this example, a PDF engine module has been used but the instructions are the same for any module as long as combining is allowed. A Release order jobinfo needs to be added.

3. Click the Add button at the bottom of the window. Another window will then appear where the JobInfo information can be specified.

4. Use the JobInfo name as set above, with index ‘0’, direction ‘ascending’ and type as ‘integer’. This will then allow the PDF engine to recognise that the TOC sheet is meant to be before the rest of the data and will combine them in the correct order.

Set a link

To make sure that only the correct documents are combined, you will also need to set a Link JobInfo. This will need to be set on Sheet 1 and the TOC sheet, so that Lasernet is able to recognize the documents to be combined. A unique document reference in the input data would be a good example to use.

To do this, follow these steps:

1. Add a JobInfo onto the relevant reference number or piece of data.

2. Give it a relevant name, for instance “LinkReference”.

3. Repeat the steps on the other sheet. Both Sheet 1 and the TOC need to have the same JobInfo to pull the correct data.

4. In the module where the combining is taking place (in this example, the PDF engine), click the Link JobInfo button in the Combining tab.

5. In the new options menu select Add.

6. Type in the name of the JobInfo that you just created on both sheets.

7. Confirm all of the menus.

8. Upload the Lasernet build and test that it works as expected.

The document will now have a TOC as the first page, which shows page numbers for new sections and how many pages are in each section.

Helpful Unhelpful

Add a comment

Please log in or register to submit a comment.

Need a password reminder?