[英]How to add/embed custom font file to FontFactory.register in iText
I need your assistant in adding a custom font to the Java Class for writing PDF. 我需要您的助手将自定义字体添加到Java类中以编写PDF。 The selected font is arial.ttf and it is located in the below path: 所选字体为arial.ttf,位于以下路径中:
Web App -> public html -> resources -> arial.ttf Web应用程序->公共html->资源-> arial.ttf
My previous code for testing was to read the font from the c: drive: 我之前的测试代码是从c:驱动器读取字体:
BaseFont bf = BaseFont.createFont("c://windows//fonts//arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Now I want to make the Web app as WAR file and to deploy it and I need to change the path from the c: drive to the path: 现在,我想将Web应用程序制作为WAR文件并进行部署,并且需要将路径从c:驱动器更改为以下路径:
Web App -> public html -> resources -> arial.ttf Web应用程序->公共html->资源-> arial.ttf
I tried also to embed the file from its location 我也尝试从其位置嵌入文件
FontFactory.register("/resources/fonts/arial.ttf");
However it always produces the below error: 但是,它始终会产生以下错误:
java.io.IOException: /resources/fonts/arial.ttf not found as file or resource. java.io.IOException:/resources/fonts/arial.ttf找不到为文件或资源。
I tried different ways to refer to the file for example: 我尝试了不同的方式来引用该文件,例如:
/public_html/resources/fonts/arial.ttf /public_html/resources/fonts/arial.ttf
../resources/fonts/arial.ttf ../resources/fonts/arial.ttf
/fonts/arial.ttf /fonts/arial.ttf
/arial.ttf /arial.ttf
But I wasn't successful 但是我没有成功
FontFactory.register(System.getProperty("file.separator")+"resources"+System.getProperty("file.separator")+"fonts"+System.getProperty("file.separator")+"arial.ttf", "my_bold_font");
Font myBoldFont = FontFactory.getFont("my_bold_font");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.