Import and Export Report File Formats

The ability to export a report to various file formats, including PDF, Microsoft Excel, HTML, Rich Text Format and delimited text, is a very important feature of Style Intelligence. In this chapter we will describe how to export a report to the various formats programmatically. We will describe the PDF export in even greater detail.

The process for generating a PDF is the same as printing to a printer through the Java API; however, we need to be aware of font mapping between the java.awt system and the PDF font equivalent. In this chapter, we discuss the default mapping provided with InetSoft products and how to change this default. We also explain how to embed a particular font within a PDF document. We describe how to create PDF bookmarks, and then discuss internationalization issues, particularly how to create PDF documents with CJK (Chinese, Japanese, Korean) characters. Next, we describe the use of the PDFServlet, which can be used to generate a report from a report template, and convert the file format of the report to the supported export formats.

After this we look into exporting to Excel, RTF or delimited text. The process for accomplishing this is similar in each case. We create an output stream and then use the inetsoft.report.io.Builder class to do the actual translation and write the report output to the specified export file format.
demo icon
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.


PDF Generation

Portable Document Format (PDF) is a document format created by Adobe for distributing documents online. It has the advantages of compact size and the availability of a free document viewer (Acrobat Reader) on many platforms.

Style Intelligence provides support for printing to a PDF file either through the use of the 'PDF3Generator' or through the use of the 'PDF4Generator'. PDF3Generator.getPDFGenerator() returns an appropriate object for the user's environment. Therefore, it is recommended that the PDF3Generator.getPDFGenerator() method be used to get an instance of the above mentioned classes, as opposed to directly instantiating the constructors.

Printing to a PDF File

Printing to a PDF file is the same as printing to a printer through the JDK PrintJob API, except in the way the PrintJob object is obtained. When printing through the JDK, a PrintJob object can be obtained through the AWT Toolkit class, which gives you a dialog to choose a printer on the system. Printing to PDF file does not require the use of the Toolkit class. Instead, a PDF3Generator or PDF4Generator object can be created directly with an output stream:

try {
      ReportSheet report = createReport();
 
      FileOutputStream output =
         new FileOutputStream("output.pdf");
      PDF3Generator pdf =
         PDF3Generator.getPDFGenerator(output);
      pdf.generate(report);
      PreviewView previewer = Previewer.createPreviewer();
      previewer.setExitOnClose(true);
      previewer.pack();
      previewer.setVisible(true);
      previewer.print(report);
      String prop = ReportEnv.getProperty("print");
      if(prop != null && prop.equals("true")) {
         previewer.printAction();
      }
   } catch(Exception e) {
      e.printStackTrace();
   }
 
public static ReportSheet createReport() {
   try {
      FileInputStream input =
         new FileInputStream("report.srt");
      Builder builder =
         Builder.getBuilder(Builder.TEMPLATE, input);
      return builder.read(".");
   } catch(Exception e) {
      e.printStackTrace();
   }
   return null;
}