PDF from HTML with only alphabetic (Latin) using itextpdf

I believe that the answer to my question is very easy for those who have had experience with this, and I thank you in advance.

Namely, I managed to export a PDF file from TextView bodyText and titleText, but my problem is that only alphabetic (Latin) letters can be seen in that PDF file, I can't see an example in Arabic, Cyrillic, Indian or Hebrew, etc. Can anyone help me, thanks !!!!!!!!

In Gradle I use: implementation 'com.itextpdf.tool:xmlworker:5.5.3'

OutputStream file = new FileOutputStream(new File("MyPath"));
Document document = new Document (PageSize.A4);

PdfWriter.getInstance(document, file);
Paragraph title = new Paragraph();
document.add(new Paragraph("\n"));
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(Html.toHtml((Spanned) bodyText.getText())));

1 answer

  • answered 2022-05-06 20:05 thomas lee ray

    I believe the problem is the font that you decided to use when exporting. Some fonts do not support non-Latin characters.

    As a result you can use fonts like:

    • CODE2000
    • Arial Unicode MS

    To use it with itextpdf I refrenced this: Click here

    font = PdfFontFactory.createFont(FontConstants.CODE2000)

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum