Certain HTML entities (arrows) are not rendered in PDF (iText)

删除回忆录丶 提交于 2019-12-11 23:50:05

问题


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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/29121766/certain-html-entities-arrows-are-not-rendered-in-pdf-itext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!