某些HTML实体(箭头)未在PDF(iText)中呈现 [英] Certain HTML entities (arrows) are not rendered in PDF (iText)

查看:163
本文介绍了某些HTML实体(箭头)未在PDF(iText)中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用XMLWorker和iText在HTML中渲染⇒ ⇔ € © →. PDF中仅显示版权和欧元符号.我使用了dafault字体和Arial,但没有成功.

I tried to render ⇒ ⇔ € © → in the HTML with the XMLWorker and iText. Only the copyright and euro symbol appear in the PDF. I used the dafault font and Arial but without success.

是否有一种方法可以渲染这些实体?有没有一种替代方法可以在文本中显示箭头?

Is there a way to get those entities rendered? Is there an alterantive way to render arrows in text?

推荐答案

您可以在 ParseHtml3中看到示例,它对我有用:

As you can see in the ParseHtml3 example, it works for me:

这是我创建PDF的代码:

This is my code to create the PDF:

public void createPdf(String file) throws IOException, DocumentException {
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    // step 3
    document.open();
    // step 4
    String str = "<html><head></head><body style=\"font-size:12.0pt; font-family:Arial\">"+
            "<p>Special symbols: &larr;  &darr; &harr; &uarr; &rarr; &euro; &copy;</p>" +
            "</body></html>";

    XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
    InputStream is = new ByteArrayInputStream(str.getBytes());
    worker.parseXHtml(writer, document, is);
    // step 5
    document.close();
}

请注意,所有实体均以小写形式编写.

Note that all entities are written in lower-case.

这篇关于某些HTML实体(箭头)未在PDF(iText)中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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