【问题标题】:Code will not accept Freesans as a resource file代码不会接受 Freesans 作为资源文件
【发布时间】:2020-02-28 01:36:37
【问题描述】:

我正在尝试将数学符号放入我的 PDF 中。错误,java.io.IOException: resources/fonts/FreeSans.ttf not found as file or resource。

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);}
}

该文件位于资源文件夹和字体下。我是不是做错了什么?

【问题讨论】:

  • 你能解压生成的jar文件,看看你的ttf是否确实嵌入其中?
  • 它还没有生成文件,只有pdf

标签: java unicode itext


【解决方案1】:

从你的错误看来你的程序没有得到文件所以抛出异常。

IOException 有 FileNotFoundException 等子类。确保文件路径正确且资源目录有ttf文件。

【讨论】:

  • 我以为我的资源文件夹是正确的,但似乎有两个资源文件夹。
猜你喜欢
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 2015-10-17
  • 1970-01-01
相关资源
最近更新 更多