Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Workaround to create a printable table of contents
moori
Hi,
I'm working with BIRT for 1 1/2 years now and I still miss a solution out of BIRT to generate a table of contents that is printable from a generated PDF file. I found help in different forums for different BIRT specific problems and today I would like to give something back. Here are the basic steps to generate a table of contents by using own and iText classes. TOC is a simple class that encapsulated TOCEntry information like title, pageNumber, level). SimpleNamedDestination, PDFReader come from iText.
1. define Bookmarks in template and encode title and level information like: <title>+":"+<level>
2. use iText:
HashMap map = SimpleNamedDestination.getNamedDestination(pdfReader, false);
//use a not iText TOC class to encapsulate TOCEntry information
TOC toc = new TOC();
String level = "-1";
String pageNumber = "1";
String title = "";
for (Object key : map.keySet()) {
String keyStr = (String) key;
//don't work with entries genenerated by another process
if (!keyStr.startsWith("__")) {
//extract encoded title and level informations
String[] titleSplitted = keyStr.split(":");
title = titleSplitted[0];
level=titleSplitted[1];
//get page information
String value = (String) map.get(key);
String[] splitted = value.split(" ");
pageNumber = splitted[0];
toc.addEntry(title , pageNumber, level);
}
}
3. String xml = toc.getXML();
//write xml into a File and use it as input for a special TOC template
Hope it helps someone.
Hilke
Find more posts tagged with
Comments
mwilliams
Hi Hilke,
Thanks for the info. Do you think you could make a posting of this for the DevShare? Possibly an example using the sample database?