Jump to content

Recommended Posts

Posted

Hi,

I'm using a java program to dynamically display a report containing thai characters which is getting mapped from comma seperated txt file containing thai chars  as the datasource.

I have added arialuni.ttf as a font.jar in to the classpath.

The PDF generated is containing charactes like "ขà¸à¹€à¸Šà¸´à¸à¸›à¸£à¸°à¸Šà¸¸à¸¡"  instead of Thai characters.

Kindly help.

I have designed the template using jaspersoftstudio 6.1.1 and when i preview the thai charaters are appearing fine.

Below is my code:

public static void main(String[] args) {
try {
 
            new TestJasper1().test("8299999","C:\Users\11111\Desktop\reports\test\8299999.txt");
} catch (Exception e) {
e.printStackTrace();
}
 
//@Override
public void test(String file,String fill) throws JRException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
try {
fill(fill);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
pdf(file);
 
}
public void fill(String fill) throws JRException, FileNotFoundException
{
File file = new File(fill);
JasperFillManager.fillReportToFile(
"Blank_A12.jasper",
null, 
new JRCsvDataSource(file)
);
 
}
public void pdf(String file) throws JRException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
 
 
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("Blank_A12.jrprint"));
 
 
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file+".pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);
 
 
 
 
JasperReportsContext jrContext=DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(jrContext).setProperty("net.sf.jasperreports.default.pdf.font.name","C:\Users\11111\Desktop\reports\arialuni.ttf");
JRPropertiesUtil.getInstance(jrContext).setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
 
exporter.setConfiguration(configuration);
 
exporter.exportReport();
 
}
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted

Hi,

I modified the font name to Arial Unicode MS at the studio, (TextField -> Show Properties) and Modified my code as below:

 

JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("C:\Users\11111\Desktop\reports\test\"+file+".pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);
 
JasperReportsContext jrContext=DefaultJasperReportsContext.getInstance();
 
JRPropertiesUtil.getInstance(jrContext).setProperty("net.sf.jasperreports.default.font.name","Arial Unicode MS");
JRPropertiesUtil.getInstance(jrContext).setProperty("net.sf.jasperreports.default.pdf.font.name","C:\Users\vi258263\Desktop\reports\arialuni.ttf");
JRPropertiesUtil.getInstance(jrContext).setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
 
I'm having the ttf, fonts.xml and jasperreports_extension.properties at the level as my class file used for generating PDF.
 
The Pdf exported via Studio now appears fine, by when exported via java code still thai characters are appearing like, à¸‚à¸à¹€à¸Šà¸´à¸à¸›à¸£à¸°à¸Šà¸¸à¸¡.
 
Kindly Help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...