飞碟字体为unicode字符

Ale*_* K. 10 css grails encoding pdf-generation flying-saucer

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

@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;
}
Run Code Online (Sandbox Code Playgroud)

ArialUni.ttf也部署到服务器.但现在我将变音字符和西里尔字符呈现为方框.如果我将-fs-pdf-encoding属性值更改为Identity-H,则可以正确呈现变音字符,但会将西里尔字符呈现为问号.

有什么字体可以用来正确渲染变音符号和西里尔字符吗?或者可能是我的CSS不知何故错了?任何提示都将非常感激.

更新1: 我也尝试过跟随css(由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';
}
Run Code Online (Sandbox Code Playgroud)

我已经添加了<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,但没有任何帮助.西里尔字符根本没有显示.可能有什么其他想法可能是什么问题?

*顺便说一下:*我正在将我的PDF打包为zip并将其发送回浏览器,如下所示:

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()
Run Code Online (Sandbox Code Playgroud)

我是否需要以某种方式考虑编码而压缩????,我喜欢这样:

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();
    }
Run Code Online (Sandbox Code Playgroud)

小智 11

我设法在java代码中"启用"unicode字符(西里尔语或捷克语),并在我的资源中提供真正的字体(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();
...
Run Code Online (Sandbox Code Playgroud)

最后,我将font-family'Calibri'添加到我的文档的css部分:

...
<style type="text/css">
    span { font-size: 11pt; font-family: Calibri; }
...
Run Code Online (Sandbox Code Playgroud)


Ale*_* K. 8

出于某种原因,它开始使用以下css和.ttf文件,它是由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;
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我将字体放入某个文件夹,让我们说"字体",它会找到字体但不会渲染字符.

  • -fs-pdf-font-encoding:Identity-H; 是关键; 它告诉Flying Saucer这是一种Unicode字体,而不是限于某些代码页的字体 (6认同)