PDF Generating Tool Support Forum

HOME   Login   Register    Search




  Subject: TTF embedding
   PostPosted: 03 Jun 2009, 16:21 
PDF viewers have a set of standard fonts like Times, Helvetica, Courier. It is guaranteeed, that PDFs with the fonts are shown correctly on any platform. It would be nice use them in full, but unfortunately there is no easy way to deal with the fonts metrics from Java. So for ISO-8859-1 charset we hardcoded the metrics tables into PD4ML, but for other characters (the rest of UNICODE space) it would be too bulky.

In order to output characters, not belong to ISO-8859-1 charset, PD4ML requires you to configure and to use TTF embedding feature. The feature is available in PD4ML Pro only (http://pd4ml.com/reference.htm#7.1)

The way TTF embedding is implemented by PD4ML may look overcomplicated at first glance. On practice it is not so; also there are reasons why TTF usage is not as transparent as in regular Java applications.

In Java you may easily instantiate Font object for any font face name and to use it for text output. But for PDF generation PD4ML needs an access not only to java.awt.Font objects, but to the corresponding physical .ttf files (to parse them and to extract a subset of used glyphs). Unfortunately Java does not offer a way to locate TTF file for a particular java.awt.Font object.

For that reason we introduced the font face -> font file mapping appraoch (with pd4fonts.properties).

The needed actions are trivial:

  1. create fonts/ directory (i.e /path/to/my/fonts/) and copy needed TTFs into it.
  2. run pd4font.properties generation command
    java -jar pd4ml.jar -configure.fonts /path/to/my/fonts/
    (as a result it should produce /path/to/my/fonts/pd4font.properties)
  3. reference /path/to/my/fonts/ directory from your Java/JSP/... code.


If you want to avoid binding to a local directory, you may pack the fonts/ directory into a JAR, place it to classpath and access them via classloader.

http://pd4ml.com/examples.zip (~2MB) contains chinese_ttf sample, which illustrates how to do that.

Very often there is no necessity to support multiple font faces, but missing of special characters (like δ, « ...) or charsets (like Cyrillic, Arabic) support is critical.

For the case we created a "quick hack" solution with easy-to-use TTF embedding.

There is a JAR with 3 fonts for serif, sansserif and monospaced types (the fonts do not contain CJK glyphs):

http://pd4ml.com/i/easyfonts/fonts.jar (~2MB)

Add the JAR to application's classpath (or put to WEB-INF/lib in webapp scenarios), address the fonts via Java classloader and specify, that the 3 fonts should be used as defaults:

pd4ml.useTTF( "java:fonts", true );
pd4ml.setDefaultTTFs("Times New Roman", "Arial", "Courier New");


(Full Java API example: http://pd4ml.com/i/easyfonts/EasyFonts.java)

JSP equivalent:

<pd4ml:usettf from="java:fonts" serif="Times New Roman" sansserif="Arial" monospace="Courier New">


The same for the PHP wrapper (assuming that fonts.jar is in the same dir where pd4ml(_demo).jar is):

passthru('java -Xmx512m -Djava.awt.headless=true -cp .:pd4ml_demo.jar:fonts.jar Pd4Php \'' . 
                   $_POST['url'] . '\' 800 A4 -ttf java:fonts 2>>stderr.txt');

// Win32 version
// passthru('java -Xmx512m -cp .;pd4ml_demo.jar;fonts.jar Pd4Cmd ' . 
//                 $_POST['url'] . ' 800 A4 -ttf fonts:jar');


  Subject: Re: TTF embedding
   PostPosted: 05 Oct 2011, 16:24 
Im using the pro version and with domino server 8.5.1
pd4ml.render(new StringReader(inputHTML), fos, new URL("file:."), "iso-8859-1");

The notesdocument is grabbed by java agent
Document usrDoc = db.getDocumentByID(strUNID);

I can't get it to display danish characters properly

i have tried this also
pd4ml.render(new StringReader(inputHTML), fos, new URL("file:."), "utf-8");

Eksample:
Kære = Kære
pÃ¥ første = på første


  Subject: Re: TTF embedding
   PostPosted: 05 Oct 2011, 16:37 
I guess inputHTML is a String object.

What does the following code print to Java console?
System.out.println(inputHTML);

Is it "Kære" or "Kære"?


  Subject: Re: TTF embedding
   PostPosted: 08 Mar 2012, 05:49 
Plz help me, How to set unicode for pdf output.? I set charset utf-8 for my html and display normal, but it create pdf output not read


  Subject: Re: TTF embedding
   PostPosted: 08 Mar 2012, 11:17 
See:
http://pd4ml.com/cookbook/pd4ml_pdf_true_type_fonts.htm


  Subject: Re: TTF embedding
   PostPosted: 02 Jul 2012, 15:06 
what are the license terms for the fonts used in http://pd4ml.com/i/easyfonts/fonts.jar? Can we use that in our commercial web application in which we generate and serve pdf to the users?


  Subject: Re: TTF embedding
   PostPosted: 02 Jul 2012, 15:14 
The fonts are taken from a Win32 distribution and published for educational purposes only. If you own a Windows license, obviously you are allowed to use the fonts in your commercial applications. http://pd4ml.com/examples.zip (chinese_ttf example) provides you with fonts.jar build-script to build the JAR from your very own TTF copies.


  Subject: Re: TTF embedding
   PostPosted: 14 Dec 2012, 13:24 
Hello,

I am trying to provide for Asian (CJK) language support in my application. While chinese works out well, the TTF embedding feature doesn't help in case of Korean or Japanese.
I followed all the steps mentioned in the online help for generating pd4fonts.properties for these font files.
In the server logs I can see font files getting resolved. Example, for japanese text, MSminchu.ttf is being loaded (as per the logs), but the generated PDF contains "??????" throughout and the PDF properties - > Font, doesn't show me msminchu font being loaded.
When I deliberately try to load chinese font for Japanese text, then I can see some of the content coming fine (that is because Chinese and Japanese languages share some symbols), but ofcourse that would not be a good solution.

What could be going wrong here? I have been at it for a longtime now. Please help!!

-Ashish


  Subject: Re: TTF embedding
   PostPosted: 17 Dec 2012, 15:54 
Please try to substitute your fonts jar with this one:
http://pd4ml.com/i/allfonts.zip (34 MB!)

unpack it and place fonts.jar to the classpath of your application (or to lib/ folder if any).
Refer the fonts this way:
pd4ml.useTTF("java:fonts", true);

And make sure the HTML has a correct meta charset directive.

Does it solve the problem?


  Subject: Re: TTF embedding with Maven build
   PostPosted: 26 Jan 2013, 01:50 
My spring application has a maven build and I want to set up fonts.jar and pd4ml.properties for this build. Can anyone help me get started?



[Reply]     [ 28 posts ]  Go to page 1, 2, 3  Next

cron
Copyright ©2004-10 zefer|org. All rights reserved. Bookmark and Share