日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

使用itext導出pdf出現的中文無法顯示的問題

作者:Java--初學者 更新時間: 2024-07-15 編程語言

1. 背景

使用如下版本的itext導出pdf時,無法顯示中文

<dependency>
	<groupId>com.itextpdf</groupId>
	<artifactId>itextpdf</artifactId>
	<version>5.5.13</version>
</dependency>

2.原因

缺少中文字體,無法識別中文

3.解決辦法

step1:導入如下依賴

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-asian</artifactId>
    <version>5.2.0</version>
</dependency>

step2:代碼如下

//設置基礎中文字體
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

//給字體添加樣式
Font fontChinese = new Font(bfChinese, 15, Font.BOLD);

//設置文字導出時的字體
document.add(new Paragraph("中文中文", fontChinese));

原文鏈接:https://blog.csdn.net/weixin_56637697/article/details/140329309

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新