使用自定义字体
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
}
}
标签:Font,BaseFont,itextpdf5,baseFont,字体,new,font
From: https://www.cnblogs.com/duchaoqun/p/itextpdf5_font.html