HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › PD4ML Tips & Tricks › TTF embedding
- This topic has 26 replies, 3 voices, and was last updated Mar 26, 2019
17:04:14 byAnonymous.
-
AuthorPosts
-
June 3, 2009 at 14:21#26202
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 (https://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:
- create fonts/ directory (i.e /path/to/my/fonts/) and copy needed TTFs into it.
- 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) - 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.
https://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):
https://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: https://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');October 5, 2011 at 14:24#27298Im 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ørsteOctober 5, 2011 at 14:37#27299I 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”?
March 8, 2012 at 03:49#27300Plz 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
March 8, 2012 at 09:17July 2, 2012 at 13:06#27302what are the license terms for the fonts used in https://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?
July 2, 2012 at 13:14#27303The 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. https://pd4ml.com/examples.zip (chinese_ttf example) provides you with fonts.jar build-script to build the JAR from your very own TTF copies.
December 14, 2012 at 11:24#27304Hello,
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
December 17, 2012 at 13:54#27305Please try to substitute your fonts jar with this one:
https://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?
January 25, 2013 at 23:50#27306My 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?
January 28, 2013 at 16:06#27307Here are good starting points:
https://pd4ml.com/reference.htm#7.1
https://pd4ml.com/cookbook/pd4ml_pdf_true_type_fonts.htmSeptember 11, 2013 at 07:16#27308i have problem with arabic i used
<pd4ml:transform screenWidth="400" pageFormat="A5" pageOrientation="landscape" debug="true" pageInsets="100,100,100,100,points" > <pd4ml:usettf from="java:fonts" serif="Times New Roman" sansserif="Arial" monospace="Courier New"/> <pd4ml:usettf from="C:/fonts"/> </pd4ml:transform>
but the arabic appear with ???? why can any one help me
September 11, 2013 at 10:11#27309You defined debug=”true” attribute. That means PD4ML prints to server’s log TTF loading diagnostics.
Can it lookup requested fonts? Can it load them? The log output should help to determine the problem reason.
September 12, 2013 at 05:23#2731013/09/13 04:19:59 version: PD4ML 381fx1 Pro DMS 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/reset.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/reset.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/reset.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/reset.css 13/09/13 04:19:59 RequestDispatcher.include() returned 6721 bytes: html, body, div, span, applet, object, i 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/template.css?<?=time()?> 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/template.css?<?=time()?> 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/template.css?<?=time()?> 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/template.css?<?=time()?> 13/09/13 04:19:59 RequestDispatcher.include() returned 62208 bytes: body { text-align: center; mar 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/black.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/black.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/black.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/black.css 13/09/13 04:19:59 RequestDispatcher.include() returned 3364 bytes: body.black #outer_wrapper { backgro 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/calender.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/calender.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/calender.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/calender.css 13/09/13 04:19:59 RequestDispatcher.include() returned 1908 bytes: .calender { width: 220px; /*he 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/ui.selectmenu.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/ui.selectmenu.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/ui.selectmenu.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/ui.selectmenu.css 13/09/13 04:19:59 RequestDispatcher.include() returned 2008 bytes: /* Selectmenu
13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/jquery-ui-1.8.6.custom.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/jquery-ui-1.8.6.custom.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/jquery-ui-1.8.6.custom.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/jquery-ui-1.8.6.custom.css 13/09/13 04:19:59 RequestDispatcher.include() returned 18640 bytes: .ui-helper-hidden { display: none; } .u 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/datePicker.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/datePicker.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/datePicker.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/datePicker.css 13/09/13 04:19:59 RequestDispatcher.include() returned 2724 bytes: table.jCalendar { border: 1px soli 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 RequestDispatcher.include() returned 858 bytes: .ac_results { padding: 0px; border: 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 RequestDispatcher.include() returned 858 bytes: .ac_results { padding: 0px; border: 13/09/13 04:19:59 looping inclusions found: file:/dp/jsps/css_ar/jquery.autocomplete.css 13/09/13 04:19:59 loading CSS file file:/dp/jsps/css_ar/keyboard.css 13/09/13 04:19:59 not yet in cache: file:/dp/jsps/css_ar/keyboard.css 13/09/13 04:19:59 Loading via HTTP Request dispatcher: /dp/jsps/css_ar/keyboard.css 13/09/13 04:19:59 Using URL without web application name: /jsps/css_ar/keyboard.css 13/09/13 04:19:59 RequestDispatcher.include() returned 7223 bytes: #keyboardInputMaster { position:absol 13/09/13 04:20:00 image not yet in cache: file:D:/isoft/projects/DPINT/src/web-online/public_html/ 13/09/13 04:20:00 image size: 7242 13/09/13 04:20:00 image size: 7242 13/09/13 04:20:00 image type of file:D:/isoft/projects/DPINT/src/web-online/public_html/ is unknown/unsupported. 13/09/13 04:20:00 can not load image: ../ 13/09/13 04:20:00 image not yet in cache: file:D:/isoft/projects/DPINT/src/web-online/public_html/Images/Button_default_hover.gif 13/09/13 04:20:00 image file:D:/isoft/projects/DPINT/src/web-online/public_html/Images/Button_default_hover.gif has zero length. 13/09/13 04:20:00 can not load image: file:D:/isoft/projects/DPINT/src/web-online/public_html/Images/Button_default_hover.gif 13/09/13 04:20:00 done in 1072ms.September 12, 2013 at 05:46#27311Note:
i used this JAR with 3 fonts for serif, sansserif and monospaced types
https://pd4ml.com/i/easyfonts/fonts.jar (~2MB)in webinf/lib
-
AuthorPosts
The forum ‘PD4ML Tips & Tricks’ is closed to new topics and replies.
