I have asked another question about this problem but I couldn't make it work. I changed my code, so now it's something like this:
import java.io.FileOutputStream;
import java.io.StringReader;
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;
public class HTM {
public static void main(String ... args ) {
try {
Document document = new Document(PageSize.LETTER);
PdfWriter pdfWriter = PdfWriter.getInstance
(document, new FileOutputStream("C:\\testpdf.pdf"));
document.open();
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
String htmlString = "<html><head>"
+ "<meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=UTF-8\" />"
+ "</head><body>"
+ "<h1>Zdravo Кристијан!</h1>"
+ "</body></html>";
worker.parseXHtml(pdfWriter, document, new StringReader(htmlString));
document.close();
System.out.println("Done.");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
My problem is that the pdf doesn't display the Cyrillic characters. I know how to make a simple pdf with different charsets and fonts but I want to convert a html file or string (in my case it is a html string) into pdf. Thanks in advance.