UTF-8编码在飞​​碟中不起作用

时间:2018-12-17 12:03:50

标签: javascript java css flying-saucer

我正在使用飞碟将html网页转换为pdf

我输入了类似的内容

<a id="link0" href="title0" title="H2">1. Economical multisignal meter DP20  &#x25a0; &#x25b2;   &#x25a0;</a>

我希望十六进制实体以字符格式显示,因为我正在使用以下代码,

public void convertHtmlToPdf(String html, String css, OutputStream out) {
    try {
        html = correctHtml(html);
        html = getFormedHTMLWithCSS(html, css);

        HtmlCleaner cleaner = new HtmlCleaner();
        TagNode rootTagNode = cleaner.clean(html);
        CleanerProperties cleanerProperties = cleaner.getProperties();
        XmlSerializer xmlSerializer = new PrettyXmlSerializer(cleanerProperties);
        String cleanedHtml = xmlSerializer.getAsString(rootTagNode);




        URL fontResourceURL = getClass().getResource("/Calibri.ttf");

        ITextRenderer r = new ITextRenderer();

        r.getFontResolver().addFont(fontResourceURL.getPath(), "UTF-8", BaseFont.EMBEDDED);
//or    r.getFontResolver().addFont(fontResourceURL.getPath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        r.setDocumentFromString(cleanedHtml);

        r.layout();
        r.createPDF(out);
        r.finishPDF();

    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage(), e);
    }
}

我也曾经尝试过使用CSS解决方案,但这两种方法都不适合我。

@font-face {

src: url('/Calibri.ttf');
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}

我无法认清我的错误。

0 个答案:

没有答案