I have a problem with pdf fonts. I have used a method for generating pdf from html which worked fine on my local machine which is windows OS, but now on linux Cyrillic text is displayed with question marks. I checked for fonts there but it turned out that there were required fonts. Now I switched to another method which is shown below.
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 = "<html><head>"
+ "<meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=UTF-8\"/>"
+ "</head>"
+ "<body>"
+ "<h4 style=\"font-family: arialuni, arial; font-size:16px; font-weight: normal; \" >"
+ "Здраво Kristijan!"
+ "</h4></body></html>";
InputStream inf = new ByteArrayInputStream(htmlContent.getBytes("UTF-8"));
XMLWorkerFontProvider fontImp = new XMLWorkerFontProvider(myFontsDir);
FontFactory.setFontImp(fontImp);
XMLWorkerHelper.getInstance().parseXHtml(writer, document, inf, null, null, fontImp);
document.close();
System.out.println("Done.");
} catch (Exception e) {
e.printStackTrace();
}
with this peace of code I am able to generate proper pdf from latin text, but cyrillic is displayed with weird characters. This happens on Windows, I haven't yet test it on Linux. Any advice for encoding or font?
Thanks in advance