how to write UTF-8 (persian) characters in pdf export of dynamic reports?

6.1k views Asked by At

I'm trying to export a report to pdf format using dynamic reports but the persian characters do not appear in pdf file. but I don't have this problem in xls files or jasper viewer. i have tried this method but it doesn't work. what should i do?

public void toPdf(String path){
    JasperPdfExporterBuilder pdfExporter = new ExporterBuilders()
    .pdfExporter(path);
    pdfExporter.setCharacterEncoding("UTF-8");
    try {

        jasperReportBuilder.toPdf(pdfExporter);
    } catch (Exception e1) {
        logger.error("failed to create PDF", e1);
    }
}

excel export : excel export

jasper viewer :

jasper viewer

PDF export : enter image description here

2

There are 2 answers

0
MoienGK On BEST ANSWER

I had the same problem and managed to solve it. You can follow my answer here. The devil is the way you handle fonts. Use this tutorial and change your encoding in fonts.xml to Identity-H (it is case sensitive!)

1
Aman_Kumar On

I am using dynamic jasper API and whenever the PDF file name i am exporting into Linux server it gets changed if it contains German umlauts character like ä even though i am taking encoding as UTF-8 or ISO-8859-14,ISO-8859-15,ISO-8859-1 etc.

changed ä to ä in dynamic jasper API(JasperConcatenatedReportBuilder) while exporting the PDF.