I am generating PDF using Grails export plugin (basically, Flying Saucer). My GSP page is an UTF-8 page (or at least properties are showing that it is UTF-8, also in the beg
For some reason it started working with following css and .ttf file, which was generated by face-kit-generator:
@font-face {
src: url('arialuni.ttf');
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
body {
font-family: Arial Unicode MS, Lucida Sans Unicode, Arial, verdana, arial, helvetica, sans-serif;
font-size: 8.8pt;
}
Weird thing is that if I put font into some folder, let say "fonts", it will find the font but characters won't be rendered.
I managed to "enable" unicode characters (cyrillic or czech) within java code and furthermore providing a true type font in my resources (CALIBRI.TTF).
import org.w3c.dom.Document;
import org.xhtmlrenderer.pdf.ITextRenderer;
import com.lowagie.text.pdf.BaseFont;
...
ITextRenderer renderer = new ITextRenderer();
URL fontResourceURL = getClass().getResource("fonts/CALIBRI.TTF");
//System.out.println("font-path:"+fontResourceURL.getPath());
/* HERE comes my solution: */
renderer.getFontResolver().addFont(fontResourceURL.getPath(),
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.setDocument(doc, null);
renderer.layout();
baos = new ByteArrayOutputStream();
renderer.createPDF(baos);
baos.flush();
result = baos.toByteArray();
...
Finally I added the font-family 'Calibri' to the css section of my document:
...
<style type="text/css">
span { font-size: 11pt; font-family: Calibri; }
...