我正在尝试将数学符号放入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);}
}
该文件在资源文件夹中,并且在字体下。我做错了吗?
从您的错误看来,您的程序未获取文件,因此引发异常。
IOException具有子类,例如FileNotFoundException。确保文件路径正确,并且资源目录中包含ttf文件。