Search code examples
javajasper-reportspdf-generationdynamic-reports

DynamicReports Changing the heading of a generated Table of Contents


This problem may be an impossibility to solve for a tool that no one seems to use but alas here we go.

I am currently in the process of generating a PDF file through the use DynamicReports that itself is based on JasperReports.

The main report is generated with various subreports,where as a table of contents is generated in the beginning

JasperReportBuilder report = report();

TableOfContentsCustomizerBuilder customTOC = new TableOfContentsCustomizerBuilder();
customTOC.setTitleStyle(ReportStyles.BOLDSTYLE);

report
    .setTemplate(Base.createTemplate())
    .tableOfContents(customTOC)
    .setDataSource(new JREmptyDataSource());

This results in a table of contents that looks like this:

Table of Contents
Page1      ……………………… 1
Page2      ……………………… 2
Page3      ……………………… 3

I wondered if there is a way or hack to change the „Table of Contents“ string, as the generated PDF is not in English. Changing the locale doesn‘t change the heading title either.

Thanks for any assistance in advance.

EDIT: Due to the repository found under https://github.com/dynamicreports I could further look into it and found it easy to solve by simply overriding the Customizer. This problem thus stemmed largely from my own inexperience as a software developer.

For any future people who find this post, simply extend the super class TableOfContentsCustomizer and override the title(); method. There you can set the text component to be anything you desire.


Solution

  • Due to the repository found under https://github.com/dynamicreports I could further look into it and found it easy to solve by simply overriding the Customizer. This problem thus stemmed largely from my own inexperience as a software developer.

    For any future people who find this post, simply extend the super class TableOfContentsCustomizer and override the title(); method. There you can set the text component to be anything you desire.