我生成PDF使用Grails導出插件(基本上,飛碟)。我的GSP頁面是一個UTF-8頁面(或者至少屬性顯示它是UTF-8,在GSP頁面的開頭還有一個<?xml version="1.0" encoding="UTF-8"?>
指令)。起初生成的PDF格式包含了變音符號「äöüõ」,但西里爾文字符從PDF中丟失(根本不顯示)。然後我按照文檔中所述添加以下內容來更改我的css文件:飛碟字體爲Unicode字符
@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,則變音符字符將正確呈現,但西里爾字符會呈現爲問號。
的可用於正確渲染兩個元音和西裏爾字母什麼字體任何想法?或者可能是我的CSS有點不對?任何提示將不勝感激。
UPD 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';
}
我已經添加<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
我還試圖運行的grails與-Dfile.encoding = UTF-8,正如這裏所提到的:http://grails.1312388.n4.nabble.com/PDF-plugin-Having-problems-with-instalation-td2297840.html,但沒有什麼幫助。西里爾字符根本不顯示。任何其他想法可能是什麼問題?
* BTW: *我打包我的PDF作爲拉鍊和類似的響應發送回到瀏覽器:
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()
我需要以某種方式考慮編碼而荏苒????,我做這樣的:
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();
}
如果你的內容類型定義爲UTF-8呢? –
您的意思是HTML內容類型? –