--- title: "How Do I Create a Table of Contents in Lasernet? - FAQ" slug: "how-do-i-create-a-table-of-contents-in-lasernet" description: "A Table of Contents (TOC) is a way of displaying the content of a generated document, especially if the content is diverse or large." tags: ["Sheet combining", "Lasernet", "Form engine", "Table of Contents", "JobInfos"] updated: 2024-11-07T13:24:47Z published: 2024-11-07T13:24:47Z canonical: "kb.lasernetgroup.com/how-do-i-create-a-table-of-contents-in-lasernet" --- > ## Documentation Index > Fetch the complete documentation index at: https://kb.lasernetgroup.com/llms.txt > Use this file to discover all available pages before exploring further. # How Do I Create a Table of Contents in Lasernet? A **Table of Contents (TOC)** is a way of displaying the content of a generated document, especially if the content is diverse or large. 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 content’s 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 this procedure: ## Lasernet Setup - Set 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. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (1)(27).png) 1. A final sheet is then needed for the **TOC**. > [!NOTE] > Note > > 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 and pages), which can then be passed on 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**). This also enables 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. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-5XR1E8OE.png) 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** checkbox. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (2)(22).png) ## Destination After activating **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 needs 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. Or ### Module Level A destination can be set on the **Form Engine**, which will send all of the output from now on. 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. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (3)(18).png) 1. Double-click the **Form Engine**, navigate to the **Destinations** tab, 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**. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (4)(22).png) The module that is set as the destination must also have **Combining** enabled in order to bring the document and the **TOC** sheet together. 1. From the main Lasernet view, open the module properties that the form is being sent to and enabled **Combining** in the **Combining** tab. ## Scripting 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. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (5)(17).png) 1. Click the **Objects** button to change the **Object type** from **Fixed text** to **Script**, and then copy the script over from the relevant sections. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (6)(21).png) For versions newer 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. ```actionscript //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 applying this script to the **Last** and **Single pages** it is possible to keep count, even with varying data input. 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. ```actionscript //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: **masterJob.getJobInfo("Sheet1PageStart");** And to display how many pages are in a section use: **masterJob.getJobInfo("Sheet1PageCount");** ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (7)(18).png) ## Place the Table of Contents on 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);` 1. 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. 1. Click the **Add** button at the bottom of the window. Another window will then appear where the **JobInfo** information can be specified. 2. Use the **JobInfo** name as set above, with index **0**, direction **ascending**, and type **integer**. This will then allow the **PDF Engine** to recognize that the **TOC** sheet is meant to be before the rest of the data and will combine them in the correct order. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image (8)(20).png) ## Set a Link To ensure 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 can recognize the documents to be combined. A unique document reference in the input data would be a good example. To do this, follow these steps: 1. Add a **JobInfo** to 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 the page numbers for new sections and the number of pages in each section.