/**
- 生成PDF------前端自定义下载地址
* @throws Exception
*/
@GetMapping("pdf2")
public void pdf2(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 第一步,实例化一个document对象
Document document = new Document(PageSize.A4);
// 第二步,设置要到出的路径
response.setContentType("application/msexcel");
response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("电子回单.pdf", "UTF-8"));
response.setCharacterEncoding("utf-8");
// 如果是浏览器通过request请求需要在浏览器中输出则使用下面方式;
ServletOutputStream out = response.getOutputStream();
// 第四步,将pdf文件输出到磁盘
PdfWriter writer = PdfWriter.getInstance(document, out);
// 第五步,打开生成的pdf文件
document.open();
// 第六步,设置内容
BisBankReceiptPdf pdf111 = bisBankReceiptPdfDao.get("AD5F79CE2D30A50B4DBC8553C4003665");
BytesToImage(pdf111.getEbillimg(),"D:\\xhw\\aa1.jpg");
Image image1 = Image.getInstance("D:\\xhw\\aaa.jpg");
document.add(image1);
// 创建table,注意这里的2是两列的意思,下面通过table.addCell添加的时候必须添加整行内容的所有列
document.newPage();
Image image2 = Image.getInstance("D:\\xhw\\aaa.jpg");
document.add(image2);
// 第七步,关闭document
document.close();
}
/**
* 批量打印
* @param e
* @param dt
* @param node
* @param config
*/
function batchPrint1(e, dt, node, config) {
parent.layer.open({
type: 2,
zIndex: -100,
shade: 0,
content: basePath + "/poi/pdf2",
success:function (layero, index) {
layer && layer.close(loadIndex);
}
});
}
/**
* 将图片字节数组转化为图片,存放到指定路径
*
* @param bytes 图片字节数组
* @param url 存放的路径
*/
public static void BytesToImage(byte[] bytes, String url){
FileImageOutputStream imageOutput = null;//打开输入流
try {
imageOutput = new FileImageOutputStream(new File(url));
imageOutput.write(bytes, 0, bytes.length);//将byte写入硬盘
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (imageOutput != null)
imageOutput.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}