Please take a look at my answer to this question: Can't get Czech characters while generating a PDF
Several things can go wrong in your code.
This is a very bad idea:
String s = "Здраво Kris";
Suppose that you send your .java file including this code to somebody who saves it as ASCII, then your source code will change into this:
String s = "Здраво Kris";
I've also seen this happen when storing a document into a source control system.
Bottom line: never use special encodings when writing source code with hard-coded strings. Either store the strings in a file using the right encoding to write and read the string, or use the unicode notation if you insist on having hard-coded data in your source code.
Even if you store the file containing this string correctly, you have to be very careful when compiling the code. If the compiler uses a different encoding, s
will be corrupted too.
You also have to make sure that you're reading the data correctly when converting the HTML to PDF. I assume that you are using XML Worker (and not the obsolete HTMLWorker
class). There are different places where you can indicate which encoding to use.
Finally, you have to make sure that you use a font that supports Cyrillic characters. For instance: if you use the default font Helvetica, nothing will be rendered.
You can also find this information in the free ebook The Best iText Questions on StackOverflow.
byte[] bytes = s.getBytes("ISO-8859-1");
– AbhishekString s
?htp.CreatePDF("<html><head><title>kristijan</title></head><body><h1>" + s + "</h1></body></html>", "kris");
alsoCreatePDF
looks like C# not Java. – Elliott Frischs
– Kristijan Iliev