PDF Report Generation:

PDF Bookmarks and Hyperlinks

PDF format supports bookmarks. Bookmarks are basically a hyperlink Table of Contents. The bookmarks can be displayed in a separate view than the document. Users can use the bookmark items to navigate in the document.

To produce PDF files with bookmarks, it is not adequate to just simulate a printer. A new class, PDF3Generator, is used to create PDF files from the report objects. The PDF3Generator uses a PDF3Printer for report data generation. It performs an extra pass at the beginning of the generation process to convert all report heading elements to PDF bookmarks.

demo
View a 2-minute demo of InetSoft's easy, agile, and robust BI software.



Listing 3. PDF Generation with Table of Contents

import inetsoft.report.pdf.*;
…
FileOutputStream pdffile = …;
PDF3Generator pdf =
   PDF3Generator.getPDFGenerator(pdffile);
ReportSheet report = …;
pdf.generate(report);
// no close() necessary

If the report contains heading elements, they are converted to PDF bookmarks, including the heading elements in the subreports. The heading elements in the subreports can be ignored by setting the 'selectiveBookmarks' property to true. If you do not want to generate bookmarks for any of the heading elements in the report, use the PDF3Printer instead.

Listing 4. Using selectiveBookmarks setting

PDF3Generator.setSelectiveBookmarks(true);
boolean selective = PDF3Generator.isSelectiveBookmarks();

The bookmarks in the PDF file can be immediately opened when the PDF file is opened. This is achieved by setting the 'pdf.open.bookmark' property to true with the help of the 'setOpenBookmark()' method in PDFPrinter. In addition, if the bookmarks need not be opened immediately upon the opening of the file, then the property can be set to false. One can also check the current value of the pdf.open.bookmark property by using the 'isOpenBookmark()' method in the PDFPrinter.



Listing 5. Using openBookmark setting

 PDFPrinter.setOpenBookmark(true);
 boolean openBookmark = PDFPrinter.isOpenBookmark(); 

Similarly, the thumbnails included in the PDF file can also be opened immediately upon opening the PDF file. This setting is controlled by the 'pdf.open.thumbnail' property which can be set using the 'setOpenThumbnail()' method in PDFPrinter. The current value of this property can be checked using 'isOpenThumbnail()' method in PDFPrinter.

Listing 6. Using openThumbnail setting

 PDFPrinter.setOpenThumbnail(true);
 boolean openThumbnail = PDFPrinter.isOpenThumbnail(); 

Note that the properties pdf.open.bookmark and pdf.open.thumbnail are mutually exclusive properties. In the case where both are set to true, pdf.open.bookmark property will take priority. The PDF document may also contain hyperlinks inserted in the report. A report property, pdf.generate.links, controls whether the hyperlinks will be generated. This property is set to true by default. If set to false, the generation time of the file will be decreased.