Hot questions for Using JasperReports in encoding


How can I set charecter encondig before export the report?

Before version 5.6.0

exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "ISO-8859-1");

With the new version, how can I set?


the API sais:

JRExporterParameter.CHARACTER_ENCODING is deprecated.

Replaced by

SimpleWriterExporterOutput.SimpleWriterExporterOutput(, String), SimpleWriterExporterOutput.SimpleWriterExporterOutput(String, String) and SimpleWriterExporterOutput.SimpleWriterExporterOutput(, String).

The property itself has following docu: public static final java.lang.String PROPERTY_CHARACTER_ENCODING Deprecated. Replaced by WriterExporterOutput.PROPERTY_CHARACTER_ENCODING.

see following link


I am using Jaspersoft Studio final version (v6.1.1). I have designed my report and it contains Turkish characters. When exporting the report from Studio as PDF Turkish characters are not shown although I've set the Studio workspace encoding to UTF-8. Also I have embed the jrxml report file in my JSF app and export the report, the result is the same.

Do I have to configure something more?


I was able to solve the problem. In the Jaspersoft Studio IDE, change encoding to UTF-8 in Window/Prefrences/General/Workspace. Afterwards click any field, parameter, or text in the IDE and from the Properties/Advanced menu select PDF/PDF Encoding. I hope it will help.


I'm using JDK 1.6.0_35 in a Java Project and I'm having a problem with java.util.ResourceBundle when recovering a properties file (encoded in ISO8859-1).

We've been asked to show an invoice with english labels but an only one, which must be written in bulgarian. The issue is that it recovers and displays only the text which is not written in Bulgarian.

I've tried to insert the text in two ways:



Neither of them worked. I'm googling and it seems like it should work with the first way (though uncomfortable, it should work), but the text written like this does not display in my PDF (I'm using Jasperreports).

When doing JasperFillManager.fillReport() my params variable contains "INVOICE=INVOICE/XXXФактураXXX", but when opening the PDF it only displays "INVOICE/XXX".

Java code:

Object obj = JRLoader.loadObject(new InputStream(someSource));
JasperReport reportMaster = (JasperReport) obj;
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(data);
JasperPrint jasperPrint = JasperFillManager.fillReport(reportMaster, params, ds);
String pathArialFont = "";
String pathArialBFont = "";
String pathArialIFont = "";
String pathArialBIFont = "";
try {
    pathArialFont = Thread.currentThread().getContextClassLoader().getResource("arial.ttf").toURI()

    pathArialBFont = Thread.currentThread().getContextClassLoader().getResource("arialbd.ttf").toURI()

    pathArialIFont = Thread.currentThread().getContextClassLoader().getResource("ariali.ttf").toURI()

    pathArialBIFont = Thread.currentThread().getContextClassLoader().getResource("arialbi.ttf").toURI()

} catch (final URISyntaxException e) {
    LOGGER.error("", e);

String arial = "Arial";
HashMap<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>();
FontKey key1 = new FontKey(arial, false, false);
PdfFont font1 = new PdfFont(pathArialFont, BaseFont.CP1252, true);

FontKey key2 = new FontKey(arial, true, false);
PdfFont font2 = new PdfFont(pathArialBFont, BaseFont.CP1252, true);

FontKey key3 = new FontKey(arial, false, true);
PdfFont font3 = new PdfFont(pathArialIFont, BaseFont.CP1252, true);
FontKey key4 = new FontKey(arial, true, true);
PdfFont font4 = new PdfFont(pathArialBIFont, BaseFont.CP1252, true);

fontMap.put(key1, font1);
fontMap.put(key2, font2);
fontMap.put(key3, font3);
fontMap.put(key4, font4);

JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, informe);
exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);

reportMaster.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");


Here you can see in one of my debuggings that the string arrives to Java code in cyrillic:


<?xml version="1.0" encoding="UTF-8"?>
    <fontFamily name="Arial">


Any clue?


I finally achieved it. I needed to change these two lines in the xml:


I changed in the Java code the BaseFont constant BaseFont.CP1252 in these lines:

new PdfFont(pathArialFont, BaseFont.IDENTITY_H, true);

and entered the text in my ISO8859-1 properties file like this:


And in the designer mode I edited the field to font "Arial Unicode MS" and checked "Pdf embedded" with Pdf Encoding "Identity-H".


I have a very strange problem while downloading a file from my Spring Controller, first of all here's the code:

@RequestMapping(value = "/id/{fileId}", method = RequestMethod.GET)
public void getFile(@PathVariable("fileId") String fileId, HttpServletResponse response) {

    // check if file exists
    if (files.containsKey(fileId)) {

        // StoredFile contains name, extension and content (byte[]) of the file
        StoredFile file = files.remove(fileId);
        response.setHeader("Content-Disposition", "attachment; filename=" + file.getFullName());

        byte[] payload = file.getContent();         

        // writing file on disk
        File f = new File("/" + fileId + ".pdf");
        try {
            FileCopyUtils.copy(payload, f);
        } catch (IOException e) {

        // send the same payload to the client for download
        try {
        } catch (IOException ex) {
            throw new RuntimeException("IOError writing file to output stream");

So, I retrieve a previously stored file, then I save its content on disk and send the same content to a client for download, but here's the strange thing: the two files are different!

The saved file is ok (it's a jasper report pdf).

The downloaded file displays nothing, and looking inside it with a binary editor I found the "EF BF BD" byte sequence that displays an UTF-8 unrecognised character.

I don't understand when the content of my byte[] is interpreted as UTF-8 and why the byte sequence is inserted; should I set the encoding somewhere even if I'm writing raw bytes inside the output stream?

I tried to set the response charactr encoding to different encoding with no change in the result, but I hadn't expected any since I'm not transferring text...

Any idea?


The code works! A colleague downloaded my branch and run the application... The downloaded file was ok. So I tried to pass the code to another colleague and then to deploy it on the test server, always getting positive results. The issue must be in some workspace or machine setting, but for sure not in the code.