Flying Saucer Unicode Font

I am creating a PDF using the Grails graphics adapter (mainly Flying Saucer). My GSP page is a UTF-8 page (or at least the properties show that it is UTF-8, there is also a directive <?xml version="1.0" encoding="UTF-8"?> at the top of the GSP page) . At first, the generated PDF correctly contained the äöüõ umlaut characters, but the Cyrillic characters were absent from the PDF (not displayed at all). Then I modified my css file as described in the documentation, adding the following:

 @font-face { src: url(ARIALUNI.TTF); -fs-pdf-font-embed: embed; -fs-pdf-font-encoding: UTF-8; } body { font-family: "Arial Unicode MS", Arial, sans-serif; } 

ArialUni.ttf is also deployed to the server. But now I get both umlaut characters and Cyrillic characters presented in the form of boxes. If I change the value of the -fs-pdf-encoding property to Identity-H, the umlaut characters are displayed correctly, but the Cyrillic characters are displayed as question marks.

Any ideas on which font can be used to correctly display both umlaut and cyrillic characters? Or maybe my CSS is somehow wrong? Any clues would be greatly appreciated.

Update 1: I also tried using css (which was created by http://fontface.codeandmore.com/ ):

 @font-face { font-family: 'ArialUnicodeMS'; src: url('arialuni.ttf'); src: url('arialuni.eot?#iefix') format('embedded-opentype'), url('arialuni.woff') format('woff'), url('arialuni.ttf') format('truetype'), url('arialuni.svg#arialuni') format('svg'); font-weight: normal; font-style: normal; -fs-pdf-font-embed: embed; -fs-pdf-font-encoding: UTF-8; } body { font-family:'ArialUnicodeMS'; } 

I added <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> I also tried to run grails with -Dfile.encoding = UTF-8, as mentioned here: http: //grails.1312388.n4.nabble.com/PDF-plugin-Having-problems-with-instalation-td2297840.html , but nothing helps. Cyrillic characters are not shown at all. Any other ideas what could be the problem?

* BTW: * I pack my PDF in zip and send it back to the browser in response like:

 response.setHeader "Content-disposition", "attachment; filename=test.zip" response.setHeader "Content-Encoding", "UTF-8" response.contentType = 'application/zip' response.outputStream << zip response.outputStream.flush() response.outputStream.close() 

Do I need to somehow consider the encoding during zipping ????, which I like:

 public static byte[] zipBytes(Map<String, ByteArrayOutputStream> fileNameToByteContentMap) throws IOException { ByteArrayOutputStream zipBaos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipBaos); fileNameToByteContentMap.eachWithIndex {String fileName, ByteArrayOutputStream baos, i -> byte[] content = baos.buf ZipEntry entry = new ZipEntry(fileName) entry.setSize(content.length) zos.putNextEntry(entry) zos.write(content) zos.closeEntry() } zos.close() return zipBaos.toByteArray(); } 
+8
css encoding pdf-generation grails flying-saucer
source share
2 answers

For some reason, it started working with the following css and .ttf files that were generated by the 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; } 

It’s strange that if I put the font in some folder, say, “fonts”, it will find the font, but the characters will not be displayed.

+6
source share

I managed to "include" Unicode characters (Cyrillic or Czech) in java code and, in addition, provide 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 "Calibri" font family to the css section of my document:

 ... <style type="text/css"> span { font-size: 11pt; font-family: Calibri; } ... 
+8
source share

All Articles