Skip to main content
Skip table of contents

How to render certain HTML entities (such as arrows) in PDF?

I tried to render ⇒ ⇔ € © → from HTML to PDF with the XMLWorker and iText. Only the copyright and euro symbol appear in the PDF. I used the default font and Arial but without success. Is there a way to get those entities rendered? Is there an alternative way to render arrows in text?

Posted on StackOverflow on Mar 18, 2015 by Code Clown

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

Screen shot showing special entities rendered in PDF

Screen shot showing special entities rendered in 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;
    // 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>" +
    XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
    InputStream is = new ByteArrayInputStream(str.getBytes());
    worker.parseXHtml(writer, document, is);
    // step 5

Note that all entities are written in lower-case, whereas you have &rArr; (which doesn't work for me either). 

Click this link if you want to see how to answer this question in iText 7.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.