Home > Java > javaTutorial > body text

How to Correctly Display Cyrillic Characters in Jasper Reports PDFs?

Patricia Arquette
Release: 2024-11-20 12:15:11
Original
326 people have browsed it

How to Correctly Display Cyrillic Characters in Jasper Reports PDFs?

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.

Code Optimization

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);
Copy after login

Additionally, specify the character encoding using the following parameter:

e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
Copy after login

Font Considerations

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.

Recommended Approach

Jasper Reports utilizes iText under the hood. To ensure optimal handling of Cyrillic characters, adhering to the following checklist is recommended:

  1. Verify that the selected TrueType Font (TTF) supports the required Cyrillic characters.
  2. Employ the correct character encoding, such as "Identity-H."
  3. Embed the font into the PDF to facilitate display on systems without the font installed.

Deprecated Method:

Previously, the following deprecated method could be used to set attributes on the textElement:

<textElement>
  <font pdfFontName="" pdfEncoding="" isPdfEmbedded="" />
  <paragraph lineSpacing="" />
</textElement>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template