Unicode 字符的飞碟字体 [英] Flying Saucer font for unicode characters

查看:24
本文介绍了Unicode 字符的飞碟字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Grails 导出插件(基本上是飞碟)生成 PDF.我的 GSP 页面是 UTF-8 页面(或者至少属性显示它是 UTF-8,也在 GSP 页面的开头有一个 <?xml version="1.0" encoding="UTF-8"?> 指令).最初生成的 PDF 正确包含变音字符äöüõ",但 PDF 中缺少西里尔字符(根本没有呈现).然后我按照文档中的描述更改了我的 css 文件,添加了以下内容:

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 beginning of the GSP page there is a <?xml version="1.0" encoding="UTF-8"?> directive). At first generated PDF properly contained umlaut characters "äöüõ", but Cyrillic characters were missing from PDF (not rendered at all). Then I've changed my css file as described in documentation by adding 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 也部署到服务器.但是现在我将变音字符和西里尔字符都呈现为框.如果我将 -fs-pdf-encoding 属性值更改为 Identity-H,则变音字符会正确呈现,但西里尔字符会呈现为问号.

ArialUni.ttf is also deployed to the server. But now I am getting both umlaut characters and Cyrillic characters rendered as boxes. If I am changing -fs-pdf-encoding property value to Identity-H then umlaut characters are rendered properly, but Cyrillic characters are rendered as question marks.

关于可以使用什么字体正确呈现变音符号和西里尔字母的任何想法?或者可能是我的 CSS 有问题?任何提示将不胜感激.

Any ideas of what font can be used to properly render both umlaut and Cyrillic characters? Or may be my CSS is somehow wrong? Any hints would be much appreciated.

更新 1:我还尝试了以下 css(由 http://fontface.codeandmore.com/ 生成):

Upd 1: I have also tried following css (which was generated 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';
}

我添加了 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>我也试图用 -Dfile.encoding=UTF-8 运行 grails,正如这里提到的:http://grails.1312388.n4.nabble.com/PDF-plugin-Having-problems-with-instalation-td2297840.html,但没有任何帮助.西里尔字符根本不显示.任何其他想法可能是什么问题?

I've added <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> I was also trying to run grails with -Dfile.encoding=UTF-8, as was 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 might be the problem?

*顺便说一句:*我正在将我的 PDF 打包为 zip 并在响应中将其发送回浏览器:

*BTW:*I am packaging my PDF as zip and sending it back to browser in the response like that:

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 encoding while zipping????, which I do like that:

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();
    }

推荐答案

出于某种原因,它开始使用以下由 face-kit-generator 生成的 css 和 .ttf 文件:

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.

这篇关于Unicode 字符的飞碟字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆