InetSoft Product Documentation: Enhanced PDF Generation Class

Embedded Fonts

The PDFPrinter is the basic implementation for generating PDF files. It only supports the base-14 fonts defined by the PDF standard. Because the base-14 fonts are guaranteed to exist in all PDF viewers, the generated files are very portable and compact. However, there are situations where other fonts need to be used in the PDF file in order to meet the formatting requirements.

For example, if the PDF document is generated using Unicode characters greater than 256, then it is a good idea to embed the fonts.

An enhanced PDF generation class, inetsoft.report.pdf.PDF3Printer, supports embedded fonts in the PDF file. Since the resulting PDF files use the same fonts as the reports, they more accurately reflect the report presentation. To support font embedding, the PDF generator needs to access the TrueType font files on the local file system. It parses the font file for font information otherwise not available from the Java API and loads the font data to embed into the PDF file.

The TrueType font directories need to be specified in the 'font.truetype.path' property. The property is a directory path and can contain multiple directories separated by a path separator (semicolon on Windows and colon on Unix). Only TrueType fonts on this path are used in PDF generation. On Windows NT, TrueType fonts are stored in the c:\winnt\fonts directory.

 ReportEnv.setProperty("font.truetype.path",
 "c:/winnt/fonts;c:/otherfonts"); 

Type 1 font information is retrieved from AFM files. AFM is the standard font format used by Adobe to store font data. AFM Files can be downloaded from the Adobe Web site. The PDF generator uses font.afm.path to search AFM files for a Type 1 font. Applications using Type 1 fonts need to package the AFM files with the application and set the font.afm.path to point to the AFM directory.

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

Listing 2. PDF Generation with Embedded Fonts

import inetsoft.report.pdf.*;
…
FileOutputStream pdffile = …;
ReportEnv.setProperty("font.truetype.path",
"c:/winnt/fonts");
PDF3Printer pdf = new PDF3Printer(pdffile);
report.print(pdf.getPrintJob());
pdf.close();

The PDF3Printer class is derived from the PDFPrinter class and shares the same methods for controlling PDF generation, such as image and text compression. It has additional methods for controlling the font embedding. By default, only font meta-data is embedded in the PDF files. For TrueType fonts, the entire font file can be embedded in the PDF file. This provides maximum portability at the price of larger file size.

pdf.setEmbedFont(true); // embed font file 

If a font's file is not found on the specified font path, it is mapped to a base-14 Font in the same way as PDFPrinter.

Previous: PDF Printer