代码将不接受Freesans作为资源文件

问题描述 投票:0回答:1

我正在尝试将数学符号放入PDF。错误java.io.IOException:找不到文件/资源​​作为资源/字体/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);}
}

该文件在资源文件夹中,并且在字体下。我做错了吗?

java unicode itext
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.