代码不会接受 Freesans 作为资源文件
Code will not accept Freesans as a resource file
我正在尝试将数学符号放入我的 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文件。
我正在尝试将数学符号放入我的 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文件。