首頁  >  文章  >  Java  >  為什麼將 Jasper 報告匯出為 PDF 時西里爾字元會損壞?

為什麼將 Jasper 報告匯出為 PDF 時西里爾字元會損壞?

Susan Sarandon
Susan Sarandon原創
2024-11-13 15:55:02875瀏覽

Why Are Cyrillic Characters Corrupted When Exporting Jasper Reports to PDF?

Troubleshooting Cyrillic Character Export Issues in Jasper Reports

Jasper Reports encounters challenges displaying Cyrillic values when exported to PDF format. While they appear correctly when exported as Excel, the text is corrupted in PDF. This issue stems from the underlying iText library utilized by Jasper Reports.

iText Character Rendering Considerations

To address this problem, consider the following steps:

  1. Ensure Font Compatibility: Verify that the TrueType Font (TTF) used supports Cyrillic characters and can render them properly in PDF format.
  2. Use Correct Encoding: Pass the correct encoding parameter to iText. For comprehensive compatibility, use "Identity-H" encoding, which allows for the inclusion of various character encodings.
  3. Embed the Font: Ensure that the font is embedded in the PDF document to allow viewing on systems that may not have the font installed locally.

JasperReport Configuration

To implement these changes in Jasper Reports:

  1. Deprecated Method: (deprecated in Jasper Reports versions 3 and above)

    • Define font attributes in the text element:
    <textElement>
      <font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
      <paragraph lineSpacing="Single"/>
    </textElement>
  2. Recommended Method: (for versions 3 and above)

    • Utilize Font Extensions: Generate a .jar file of your font extension using tools like iReport or JasperSoft Studio. Include this .jar file in your classpath.

By addressing these considerations, you can resolve the issue of missing Cyrillic values when exporting Jasper Reports to PDF format.

以上是為什麼將 Jasper 報告匯出為 PDF 時西里爾字元會損壞?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn