iText pdf library
Website search

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

This question was originally asked on Mar 18, '15 by aggsol

When we discussed fonts in chapter 6, we mentioned that Symbol and ZapfDingbats don't play well with HTML, and that other fonts are better suited when you need special symbols. When we discussed internationalization, we noticed that we can render Greek characters without the need for a font as Symbol. The C07E12_SpecialCharacters example shows that we don't need ZapfDingbats to render arrows, smileys, or any other special symbol. Other fonts such as FreeSans and FreeSerif are used instead.

Special characters in a PDF

Special characters in a PDF

The HTML code uses HTML entities to represent these special symbols:

public static final String HTML = "<html><head></head>" +
    "<body style=\"font-size:12.0pt; font-family:Arial\">" +
    "<p>Special symbols: " +
    "&larr;  &darr; &harr; &uarr; &rarr; &euro; &copy; &#9786;</p>" +
    "</body></html>";

The pdfHTML add-on is perfectly capable of parsing such entities. No special settings are needed in the createPdf() method:

public void createPdf(String html, String dest) throws IOException {
    HtmlConverter.convertToPdf(html, new FileOutputStream(dest));
}

 If your application runs on a Windows machine, you can also use system fonts such as symbol.ttf and several WebDings and WingDings fonts if you need a symbol or special character.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now