Jump to content
Changes to the Jaspersoft community edition download ×

How to access ToC numbering at each heading


Recommended Posts

Hi Community,

I user Jasperreports to create a  report book.

Book, ToC, Contents, Custom Datasources etc. work like a charm. Also, ToC has correct numbering for bookmarks (1. Foo, 1.1 FooSub, 1.1.1 FooSubSub, 2. Bar, 2.1 BarSub etc.).

But I failed to add the bookmark numberings to the heading itself. How can I get a heading - e.g. "FooSub" - to print "1.1 FooSub"? It seems like there is no Varaibale, Field or Parameter for that number.


Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.

Link to comment
Share on other sites


if you have multiple reports and sub-reports you find an example on how to create Page Numbers for the whole results here:


you can use the following syntax:

"Page "+$V{MASTER_CURRENT_PAGE}+" of"   


and change the evaluation time of the element to "Master" 


Let me know if that will solve your problem. THX 

Regards TT







Link to comment
Share on other sites

My TOC.jrxml is below :)
<?xml version="1.0" encoding="UTF-8"?>																															]]>	</queryString>	<field name="level" class="java.lang.Integer"/>	<field name="label" class="java.lang.String"/>	<field name="pageIndex" class="java.lang.Integer"/>	<variable name="l2" class="java.lang.Integer">		<variableExpression><![CDATA[$F{level} == 1 ? 0 : ($F{level} == 2 ? ($V{l2} + 1) : $V{l2})				OR($F{level} == 1,$F{level} == 2) ? 0 : ($F{level} == 3 ? ($V{l3} + 1) : $V{l3})				$F{level} == 1 ? ($V{l1} + 1) : $V{l1}		0				OR($F{level} == 1,$F{level} == 2, $F{level} == 3) ? 0 : ($F{level} == 4 ? ($V{l4} + 1) : $V{l4})																																																																																"Inhaltsverzeichnis"												new Boolean($V{PAGE_NUMBER}.intValue()>1)																																											$P{heading2}																											$P{heading1}														$P{logo}															$F{level} == 1																																																																												$F{label}				$F{label}																																																																										$V{PAGE_NUMBER} + $F{pageIndex} + 1				$F{label}																																																																															$V{l1} + "."				$F{label}																										$F{level} == 2																																																																							$F{label}				$F{label}																																																																										$V{PAGE_NUMBER} + $F{pageIndex} + 1				$F{label}																																																																															$V{l1} + "."+$V{l2}				$F{label}																$F{level} == 3																																						$F{label}				$F{label}																																									$V{PAGE_NUMBER} + $F{pageIndex} + 1				$F{label}																																																																															$V{l1} + "."+$V{l2} + "."+$V{l3}				$F{label}										$F{level} == 4																																																																												$V{l1} + "."+$V{l2} + "."+$V{l3}+ "."+$V{l4}				$F{label}																																									$F{label}				$F{label}																																									$V{PAGE_NUMBER} + $F{pageIndex} + 1				$F{label}																																				"Seite "+$V{MASTER_CURRENT_PAGE}+" von "+$V{MASTER_TOTAL_PAGES}																																					$P{left_footer}						[/code]


Link to comment
Share on other sites


there is no "out of the box" and simple way to reuse the Numbering from the TOC in a report or sub-report, but there is a way to send the index information from the TOC to the reports used in the Workbook. Please find attached a Zip that contains an example with all needed files base on our sampledb and an example PDF that shows the final result using the numbering for 2 Level of the TOC like the one you are looking for. 

bildschirmfoto_2023-07-26_um_10_42_16.thumb.png.f151e11900fb4bc1ae20bcf19745e17d.png  bildschirmfoto_2023-07-26_um_10_42_34.thumb.png.4e2492a6fe0676ea8aa0667762ab57ec.png

How to description:

Open the Report Book and select the Report (1) edit Parameters (2) and add the Name: index (3) and the expression  $V{REPORT_COUNT} + 1   (4)


Using the the index from the TOC for Level 1 Titel in your Report

Now you can edit the expression for the Titel and add the $P{index} as first element like this:

$P{index} + ". Shipments to " + $P{Country}

Evaluation Time: Now


To generate a 2. Level Titel (for example 1.2  etc.)  you have to generate a new Variable that will create the Number for each Sub-Group like this:

In our Example Level 1 = Country and Level 2 = City 


To get the 2. Level Text (1.1  1.2. etc) you have to select the Group Field (1) open the Expression (2) and add the $P{index}  and the new Variable $V{City_Index} to your Expression (3) like this:

$P{index} + "."+($V{City_Index}  + 1) + " " + $F{ShipCity}


That is all you have to do to get the Numbering from the TOC to  your Report Details.

If you want a 3. Level you have to create an additional Variable that is linked to the Increment Type of the 3. Group of you Report. 


Please let me know if this will work for you. 

Regards TT








Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...