4

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

MohammadZoghi
  • 578
  • 1
  • 5
  • 17
  • Are you using the [Font Extensions](http://jasperreports.sourceforge.net/sample.reference/fonts/index.html#fontextensions)? – Alex K Dec 11 '13 at 13:17
  • I don't use jasper directly but i set fonts to both english and persian fonts using dynamic reports' StyleBuilder.setFontName(String) method. it changes the font in xls and jasper viewer but makes no difference in pdf! – MohammadZoghi Dec 11 '13 at 13:33
  • Are you using the *jrxml* file? What is your code for adding fields in *Detail* band? – Alex K Dec 11 '13 at 13:53
  • @AlexK no I don't use jrxml file. I use jasperReportBuilder.addColumn method from dynamic reports. i use SelectQuery from [squiggle sql](https://code.google.com/p/squiggle-sql/wiki/Tutorial) to set the dataSource jasperReportBuilder.setDataSource(selectQuery.toString(), JDBCConnection) – MohammadZoghi Dec 11 '13 at 14:19
  • 1
    try this http://www.dailyfreecode.com/forum/problem-farsi-fonts-dynamic-text-20522.aspx – MoienGK Dec 11 '13 at 15:36
  • @dave thanks but not working. – MohammadZoghi Dec 11 '13 at 15:43

2 Answers2

4

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!)

Salek
  • 193
  • 4
  • 14
MoienGK
  • 4,180
  • 9
  • 49
  • 89
0

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.

  • problem solved .i am using 'Arial Unicode MS' font and added ARIALUNI.TTF ,fonts.xml file in class-path. font.xml contains below code- ARIALUNI.TTF Identity-H true – Aman_Kumar Sep 26 '17 at 07:13