vijaypr.chak Posted November 5, 2015 Posted November 5, 2015 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();} //@Overridepublic 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(); }
hozawa Posted November 5, 2015 Posted November 5, 2015 Hint:Check what you're setting on "net.sf.jasperreports.default.pdf.font.name" to make sure that's what you're setting in Jaspersoft Studio.
vijaypr.chak Posted November 6, 2015 Author Posted November 6, 2015 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now