public String ExportPdf{
Calendar calendar = Calendar.getInstance();
String filename = String.valueOf(calendar.getTimeInMillis()) + ".pdf";// 文件名字
String path = "\\" + filename;
filename = filedir + path;// 生成的pdf文件保存路径
System.out.println("fileame123===" + filename);
//写入前把文件都删除
System.out.println("fileame===" + filedir+"file");
//WritePdf.deleteFileInFolder(filedir+"file");
//导出pdf
Document document = new Document();
//获取图片的路径 image为jfree生成的图片
try {
String imagePath =ServletActionContext.getServletContext().getRealPath(imageDir);
File imagePath1 = new File(imagePath);
// 如果这个目录不存在,则创建它。
if (!imagePath1.exists())
imagePath1.mkdir();
double[] d1 =(double[])this.getRequest().getSession().getAttribute("dou");//预测数据
getColumnPath(imagePath,d1);//把图片生成到指定的图片中
Image jpg = Image.getInstance(imagePath+"\\fruit4.jpeg");
//Image jpg = Image.getInstance(imagePath);
Table table=new Table(2);
table.setBorderWidth(1); //将边框宽度设为0
table.setBorderColor(new Color(255, 255, 255)); //将边框的颜色设置为白色
//将图片加载在表格中
table.addCell(new Cell(jpg));
table.addCell(new PDFParagraph("acf图"));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter.getInstance(document, new FileOutputStream(filename));//pdf路径和文档内容绑定
document.open();
//通过表格进行输出图片的内容
document.add(table);
document.close();
} catch (BadElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//在页面显示
//String path1 = path.replace("\\", "\\\\");
// request.setAttribute("path", path1);
//response.sendRedirect(path);
}