Known issues

  • Bidirectional scripts are supported with some restrictions. PD4ML can not do correctly glyphs shaping yet for the texts in page header/footer areas as well as in the form elements (like button captions). 
     
  • To use PD4ML with bidirectional scripts on UNIX platform, you should correctly install referred TTFs to be known by Java. See the document: http://java.sun.com/j2se/1.3/docs/guide/intl/addingfonts.html#adding 
     
  • On UNIX-derived platforms TTF font Wingdings is not supported for the time being.

A lot of TTF fonts have only plain style defined. For example NSimSun font has no bold or italic glyphs pre-defined.

“If the font in a document uses a bold or italic style, but there is no font data for that style, the host operating system will synthesize the style.” 

That works for native applications like MS Internet Explorer for direct text output, but unfortunately a synthesized font is not accessible from Java application as binary font data. PD4ML needs a .ttf file or an equivalent to parse, extract glyph definitions for used characters and to embed them to the resulting PDF.

In theory as a possible solution you can use a third-party TTF management tool to synthesize italic style of NSimSun and to save it as
NSimSunItalic.ttf and to register in pd4fonts.properties:

NSimSun\ Italic=NSimSunItalic.ttf

Or simply choose a similar italic font, and register it as above.

The same can be done for “NSimSun\ Bold\ Italic”

Embedding fonts to PDF from JSP

<%@ taglib uri=”/WEB-INF/tlds/pd4ml.tld” prefix=”pd4ml” %><%@page
contentType=”text/html; charset=UTF-8″%><pd4ml:transform
screenWidth=”400″
pageFormat=”A5″
pageOrientation=”landscape”
pageInsets=”15,15,15,15,points”
inline=”true”>

<!–
TODO:
1. adjust fonts directory below.
2. make sure that the directory contains pd4fonts.properties file
3. for more info see PD4ML.useTTF( String, boolean ) Java API docs
–>
<pd4ml:usettf from=”/windows/fonts”/>


<html>
<head>
<title>PD4ML embedded fonts test</title>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
</head>
<body>
<font face="Tahoma">Hello, World!</font><br>
<font face="Verdana">Привет, Мир!</font><br>
<font face="SimSun">我招呼您, 世界!</font><br>
</body>
</html>
</pd4ml:transform>

Note: Explicit and correct charset setting like <%@page contentType=”text/html; charset=UTF-8″%> is mandatory for JSP.

Embedding fonts to PDF from Java API

...
File tempFile = File.createTempFile( "pd4ml", ".pdf" );
java.io.FileOutputStream fos = new java.io.FileOutputStream( tempFile );

PD4ML pd4ml = new PD4ML();
pd4ml.setHtmlWidth( 800 );
pd4ml.useAdobeFontMetrics( true );

pd4ml.useTTF( "/windows/fonts", true );

pd4ml.render( "http://www.yahoo.com", fos );

String pdfFile = tempFile.getAbsolutePath();
String viewcmd = 
    "\\Program Files\\Adobe\\Acrobat 6.0\\Reader\\AcroRd32.exe " + pdfFile;

Runtime.getRuntime().exec( viewcmd );

...

Configuring fonts directory

PD4ML takes TTF fonts from a directory passed to PD4ML runtime as a parameter. The directory should contain TTF font files and a special mapping file: pd4fonts.properties. The file maps font names to particular font files located in the directory. The format of a configuration file entry is following:

Font\ Name=fontfile.ttf

Spaces in font names are escaped with ‘\’
Example:

Bookman\ Old\ Style\ Bold\ Italic=BOOKOSBI.TTF

The config file can be generated automatically with the following command line:

java -jar pd4ml.jar -configure.fonts /fonts/directory

(please replace ‘/fonts/directory’ by the path to the fonts directory on your system)

If you use Windows platform, than it can be an option to generate the file directly in %WINDOWS%/fonts directory.
For UNIX derived systems we would recommend to copy all needed TTF fonts to $JAVA_HOME/jre/lib/font directory and to generate pd4fonts.properties file there. See more about adding TTF fonts to Java here: http://java.sun.com/j2se/1.3/docs/guide/intl/addingfonts.html#adding.

After a config file generation completed please edit the generated file (/fonts/directory/pd4fonts.properties) manually in order to remove any font entries, that are not allowed to be embedded. You may use a special Win32 tool, mentioned in the document http://www.microsoft.com/typography/TrueTypeEmbedding.mspx, in order to determine if a particular font protected by copyright against embedding.

 

System requirements

  • PD4ML Pro does not support Java runtimes older than v1.4.2. (Update: since v3.x PD4ML Pro supports JDK 1.3.1)
  • Referred TTF fonts should be UNICODE