JasperReportsで帳票を作成していて、PDFで文字がうまく出力されないことがありました。その時、対策したことを載せておきます。
※日本語の文字列だけがうまく出力されないケースでも、この対策で回避できることがあります。
事象
まずは発生した事象の確認。
作成したレポートをプレビューで表示する。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-4-1-1024x577.jpg)
プレビューでは、うまく表示されている。「Export As PDF」で出力してみる。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-4-1024x575.png)
文字列部分が表示されない。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-5.png)
対策
フォントを「IPA Font」にすると正常になりました。以下、フォントを適用する手順を記載します。
①IPAからフォントをダウンロードする
以下のIPAのダウンロードページにアクセスする。
https://moji.or.jp/ipafont/ipafontdownload/
最新版をダウンロードする。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-3-1024x714.png)
②JasperStudio(Eclipse)からダウンロードしたフォントを取り込む。
ウインドウ > 設定 > Jaspersoft Studio > フォント
「Add From Path」ボタンを押す。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-6.png)
ダウンロードしたフォントがあるフォルダを選択する。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-11.png)
![](https://mashimashi.net/wp-content/uploads/2021/10/image-12.png)
フォントが追加されていることを確認し、「適用して閉じる」を押す。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-13.png)
③帳票のフォントをIPAに変更する。※今回は、「IPAex明朝」を設定。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-14-1024x577.jpg)
フォントの変更は、ソースタブで開いて、「font fontName」で検索していくと楽かも。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-14-1024x576.png)
再度試してみる
プレビューで「Export As PDF」で出力してみる。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-15-1024x577.png)
うまく出力されました!
※一部、データをマスクしています。
![](https://mashimashi.net/wp-content/uploads/2021/10/image-16-845x1024.png)
コメント