I am using iText 4.0.2 version for pdf generation. I have some characters/symbols to print like ∈, ∩, ∑, ∫, ∆ (Mathematical symbols) and many others. My code :
Document document = new Document(PageSize.A4, 60, 60, 60, 60);
try
{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/adeel/experiment.pdf"));
document.open();
String str = "this string will contains special character like this ∈, ∩, ∑, ∫, ∆";
BaseFont bfTimes = null;
try {
bfTimes = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Font fontnormal = new Font(bfTimes, 12, Font.NORMAL, Color.BLACK);
Paragraph para = new Paragraph(str, fontnormal);
document.add(para);
document.close();
writer.close();
System.out.println("Done!");
} catch (DocumentException e)
{
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
In the above code I am putting all the symbols in str
and generating the pdf file. In place of symbols I tried putting unicode characters in str
for the symbols but It didn't worked as well.