itextpdf5 Font

使用自定义字体

package aoye
import com.itextpdf.text.BaseColor
import com.itextpdf.text.Font
import com.itextpdf.text.FontFactory
import com.itextpdf.text.pdf.BaseFont
class CustomFontAlibaba {
CustomColor customColor = new CustomColor()
// 使用外部字体
String fontPath = getClass().getClassLoader().getResource("Alibaba-PuHuiTi-Regular.ttf")
// 直接使用该字体
Font font = FontFactory.getFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
// 创建基本字体
BaseFont baseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
Font font9 = new Font(baseFont, 9)
// 标题的字体
Font getFont17D5WhiteBOLD() {
Font font = new Font(baseFont, 17.5, Font.BOLD)
font.color = customColor.getWhite()
return font
}
// 标题下的编号字体
Font getFont8White() {
Font font = new Font(baseFont, 8)
font.color = customColor.getWhite()
return font
}
// 标题下的编号字体
Font getFont9Gray() {
Font font = new Font(baseFont, 9)
font.color = CustomColor.getGrey1()
return font
}
// 正文一级标题字体
Font getWhiteBoldFont11() {
Font font = new Font(baseFont, 11, Font.BOLD) // 正文标题字体
font.color = customColor.getWhite()
return font
}
Font getFont10D5(boolean bold, BaseColor fontColor) {
Font font = new Font(baseFont, 10.5) // 正文标题字体
if (bold){
font.setStyle(Font.BOLD)
}
if (fontColor){
font.setColor(fontColor)
}
return font
}
}
posted @   duchaoqun  阅读(180)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2019-11-28 00 - 准备 Anaconda 环境
2019-11-28 0x06 - Nginx 负载均衡会话保持
点击右上角即可分享
微信分享提示