IText5填充PDF表单使用自定义字体中文生效而英文和数字不生效?
为什么使用IText5填充PDF时,使用自定义字体(特别是某些新兴的字体)时中文生效,英文和数字不生效?
查了相关资料,发现无果,或者都不生效。
看了api接口文档,发现有解决方案,特地记录一下:
在 com.itextpdf.text.pdf.AcroFields#setFieldProperty(java.lang.String, java.lang.String, java.lang.Object, int[])中可设置字体。
具体是这么描述的:
Sets a field property. Valid property names are:
textfont - sets the text font. The value for this entry is a BaseFont.
textcolor - sets the text color. The value for this entry is a BaseColor.
textsize - sets the text size. The value for this entry is a Float.
bgcolor - sets the background color. The value for this entry is a BaseColor. If null removes the background.
bordercolor - sets the border color. The value for this entry is a BaseColor. If null removes the border.
见名之意:设置文本字体,设置的值即是咱们加载的自定义字体,如:
BaseFont font = BaseFont.createFont("/path/AlibabaPuHuiTi-3-45-Light.ttf",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
发现生效了。