我正在尝试将数学符号放入我的 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/