Exporting Cyrillic Values in Jasper Reports PDF
When exporting a Jasper report to PDF, users may encounter an issue where Cyrillic characters fail to display correctly. This discrepancy occurs despite the characters being displayed accurately when exported to Excel.
To resolve this issue, it is crucial to ensure that the font used supports Cyrillic characters and that the correct character encoding is applied.
The following code parameters should be included when exporting to PDF:
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint); e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream); e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
Additionally, specify the character encoding using the following parameter:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
It is important to note that the font used in the report must support Cyrillic characters and must be embedded into the PDF to ensure proper display on systems that may not have the font installed.
Jasper Reports utilizes iText under the hood. To ensure optimal handling of Cyrillic characters, adhering to the following checklist is recommended:
Deprecated Method:
Previously, the following deprecated method could be used to set attributes on the textElement:
<textElement> <font pdfFontName="" pdfEncoding="" isPdfEmbedded="" /> <paragraph lineSpacing="" /> </textElement>
Non-Deprecated Method (v3-6):
In more recent versions, the preferred approach involves adding Font Extensions, which can be generated using tools like iReport or JasperSoft Studio. These extensions enable the inclusion of font resources in the classpath, ensuring proper display of Cyrillic characters.
The above is the detailed content of How to Correctly Display Cyrillic Characters in Jasper Reports PDFs?. For more information, please follow other related articles on the PHP Chinese website!