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 you may need other fonts in order to meet formatting requirements.
For example, if the PDF document is generated using Unicode characters greater than 256, it is a good idea to embed the fonts.
An enhanced PDF generation class, 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 using the font.truetype.path property. The property is a directory path, e.g., c:\winnt\fonts, 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.
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.
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.
| << Font Handling in PDF (Base-14 Fonts) | © 1996-2013 InetSoft Technology Corporation (v11.5) | PDF Bookmarks and Hyperlinks >> |