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
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:
OutputStream file = new FileOutputStream(new File("MyPath")); Document document = new Document (PageSize.A4); PdfWriter.getInstance(document, file); document.open(); Paragraph title = new Paragraph(); title.add(titleText.getText().toString()); title.setSpacingAfter(12.0f); title.setAlignment(Element.ALIGN_CENTER); document.add(title); document.add(new Paragraph("\n")); HTMLWorker htmlWorker = new HTMLWorker(document); htmlWorker.parse(new StringReader(Html.toHtml((Spanned) bodyText.getText()))); document.close(); file.close();
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:
- Arial Unicode MS
To use it with itextpdf I refrenced this: Click here
font = PdfFontFactory.createFont(FontConstants.CODE2000) text1.setFont(font);