Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JasperReport: Persian Report in PDF

  Asked By: Seth    Date: Feb 11    Category: Java    Views: 2225
  

I want to create a PDF report file using JasperReport containing data
with persian character fetched from database.
Any experience in this regard?

The HTML version works good with persian characters but PDF one does
not show persian characters.
This is my sample code for PDF:


File reportFile;
Map parameters = new HashMap();
String fileName = "D:/RD/web/report/test.jasper";
String outFileName;

try {
Locale locale = new Locale("fa", "", "");
parameters.put(JRParameter.REPORT_LOCALE, locale);
reportFile = new File(fileName);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject
(reportFile.getPath());

JasperPrint jasperPrint = JasperFillManager.fillReport
(jasperReport, parameters, MyConnection.con);

JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT,
jasperPrint);
outFileName = "D:/RD/web/report/test.pdf";
exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME,
outFileName);
exporter.setParameter
(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");

exporter.exportReport();

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Stacy Cunningham     Answered On: Feb 11

Just use Identity-H as your PDF Encoding.
To define your PDF Encoding you can define a style then use it in your
report elements.

Example:


// Define Your Style
JRDesignStyle normalStyle = new JRDesignStyle();
normalStyle.setName("Arial_Normal");
normalStyle.setDefault(true);
normalStyle.setFontName("C:/WINDOWS/Fonts/tahoma.ttf");
normalStyle.setFontSize(9);
normalStyle.setPdfFontName("C:/WINDOWS/Fonts/tahoma.ttf");
normalStyle.setPdfEncoding("Identity-H");
normalStyle.setPdfEmbedded(true);
normalStyle.setBlankWhenNull(true);
jasperDesign.addStyle(normalStyle);

// Use the defined style in you elements
staticText = new JRDesignStaticText();
staticText.setX(x1);
staticText.setY(0);
staticText.setWidth(sizes[i]);
staticText.setHeight(15);
staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
staticText.setStyle(normalStyle);
staticText.setText(fieldName);

 
Answer #2    Answered By: Jimmie Ramirez     Answered On: Feb 11

We already did all your mentioned trips in JasperReport Editor and no success.
However I used your source code  and again no success.
When we compile and run in JasperReport Editor, the PDF output does not show persian  characters while english ones are ok.

 
Didn't find what you were looking for? Find more on JasperReport: Persian Report in PDF Or get search suggestion and latest updates.




Tagged: