飞碟添加嵌入式字体不能在tomcat上运行

时间:2016-08-25 23:14:52

标签: java fonts itext flying-saucer

我使用Flying Saucer将XHTML转换为PDF文件。我的问题是我在PDF中有一些丢失的土耳其字符。但是我不明白,我在junit测试中没有任何问题。我可以将XHTML文件转换为包含所有土耳其语字符的PDF,没有任何问题。但如果我在Tomcat上部署的Applicaton上执行相同的操作,则所有土耳其字符都会丢失。

我做了一些调试,发现' /fonts/arialuni.ttf'在两种情况下均可找到。我找到了一些相关的线程和itext doc并尝试了所有这些。

http://developers.itextpdf.com/question/how-can-i-load-font-web-infresourcesfontsfoobarttf

Flying Saucer font for unicode characters

转换和添加字体的代码

            String path2 = "/fonts/arialuni.ttf";

           //FontFactory.register(path2);
            ITextRenderer renderer = new ITextRenderer();
          // renderer.getFontResolver().addFontDirectory(path2,true);

            renderer.getFontResolver().addFont(path2, BaseFont.IDENTITY_H,BaseFont.EMBEDDED);


            renderer.setDocumentFromString(docElem.html());
            renderer.layout();
            renderer.createPDF(os);
            renderer.finishPDF();
            baoOut.flush();

并且还为CSS应用了以下内容。但结果仍然相同。



@font-face {
    src: url('arialuni.ttf'); <!--src: url('/fonts/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;
}
&#13;
&#13;
&#13;

有谁知道,为什么找到arialuni.tff但是没有在Tomcat上使用?

1 个答案:

答案 0 :(得分:0)

终于解决了。在某些地方我正在使用

InputStream htmlIS = IOUtils.toInputStream(invoiceHtml);

代替

InputStream htmlIS = IOUtils.toInputStream(invoiceHtml, "UTF-8");

造成了问题。

相关问题