当我调用:
时public class App
{
public static void main( String[] args )
{
try {
TemplateGenerator tg = new TemplateGenerator();
tg.generateTemplateFile();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
和
public class TemplateGenerator {
Font cellTitle=null;
public void generateTemplateFile() throws IOException, DocumentException {
File file = new File(Properties.TEMPLATE_FILE);
file.getParentFile().mkdirs();
this.createPdf(Properties.TEMPLATE_FILE);
}
private void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.setPageSize(this.setupPageSize(Properties.WIDTH_MM,
Properties.HEIGHT_MM));
document.setMargins(2, 2, 2, 2);
document.open();
document.add(buildFrames());
document.close();
}
private Rectangle setupPageSize(Float width, Float height){
return new Rectangle( Utilities.millimetersToPoints(width),
Utilities.millimetersToPoints(height));
}
private void setupFonts() throws IOException, DocumentException {
cellTitle = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYBLACK);
}
private PdfPTable buildFrames(){
PdfPTable table;
table = null;
try{
Font fontH1 = new Font(Font.FontFamily.COURIER, 16, Font.NORMAL);
table = new PdfPTable(1);
table.addCell(new PdfPCell(new Phrase("aaa",fontH1)));
}catch (Exception e){
e.printStackTrace();
}
return table;
}
}
我打印了单元格但为空即。没有“aaa”tekst。无论细胞文本没有出现。我想知道什么是错误没有错误。我得到了存储在src / main / resources中的文件,具有664访问权限。有什么问题?