How to make Cyrillic characters display properly when converting HTML to PDF?

I have a problem with PDF fonts. I am generating PDF from HTML and that worked fine on my local machine, which has Windows as OS. But now I deploy my application on a Linux server and my Cyrillic te

I have a problem with PDF fonts. I am generating PDF from HTML and that worked fine on my local machine, which has Windows as OS. But now I deploy my application on a Linux server and my Cyrillic text is displayed as question marks.

This is my code:

Document document = new Document(PageSize.A4);
String myFontsDir = "C:\\";
String filePath = AppProperties.downloadLocation + "Order_" + orderID + ".pdf";
try {
    OutputStream file = new FileOutputStream(new File(filePath));
    PdfWriter writer = PdfWriter.getInstance(document, file);
    int iResult = FontFactory.registerDirectory(myFontsDir);
    if (iResult == 0) {
        System.out.println("TestPDF(): Could not register font directory " + myFontsDir);
    } else {
        System.out.println("TestPDF(): Registered font directory " + myFontsDir);
    }
    document.open();
    String htmlContent = ""
        + "\"content-type\"" content=\""application/xhtml+xml; charset=UTF-8\""/>""


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