java - 代码不会接受 Freesans 作为资源文件

标签 java unicode itext

我正在尝试将数学符号放入我的 PDF 中。错误 java.io.IOException:未找到 resources/fonts/FreeSans.ttf 文件或资源。

public class CreateTable {
    public static final String FONT = "resources/fonts/FreeSans.ttf";
    public static void main(String[] args) throws FileNotFoundException, DocumentException {


        BaseFont bf = null;
        try {
            bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Font f = new Font(bf, 12);
        Document document = new Document();  // Whole page is consider as docuemnt so we need object .
        PdfPTable table = new PdfPTable(7);  //Create Table Object

        //Adding alignment and cells with defining rows
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell("");
        table.addCell("Age \u00AC");
        table.addCell("Location");
        table.addCell("Anotherline");
        table.setHeaderRows(1);}
}

该文件位于资源文件夹中的字体下。我做错了什么吗?

最佳答案

从您的错误来看,您的程序似乎没有获取文件,因此引发异常。

IOException 有子类,例如 FileNotFoundException 。确保文件路径正确并且资源目录中有ttf文件。

关于java - 代码不会接受 Freesans 作为资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60444125/

相关文章:

c# - IText AllowAssembly 和 StandardEncryption

java - 递归DRY代码,计算月份中的天数,Java

java - 如何在Android中解析JSON数组(不是Json对象)

c++ - C++0x 中没有 Unicode 流?为什么?

itext pdfHtml : set margins

java - xslt 转换不关闭标签

java - 无法自动启动 bean tomcat IntelliJ

java - 为什么在这个例子中没有调用子类方法,因为它在 Java 的动态多态中被调用?

unicode - 转到unicode代码点

python - 在 Python 2.7 中从 Unicode 转换字符串时遇到问题?