【发布时间】: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