String phantomjs_path =CfgTool.getWebRootPath() + “phantomjs/”;
String report_path = reportService.getReportPath(task_id);
File phantomjs = new File(phantomjs_path + “phantomjs”);
if (!phantomjs.exists()) {
throw new FileNotExistException().addScene(“FILE”, phantomjs.getPath());
}
StringBuilder cmd = new StringBuilder();
cmd.append(phantomjs_path).append(“phantomjs “)
.append(phantomjs_path).append(“html2pdf.js “)
.append(url).append(” “)
.append(report_path).append(task_id).append(“.pdf”);
if (!Assert.isEmpty(input.getPaper_size())) {
cmd.append(” “).append(input.getPaper_size());
}
logger.debug(“开始导出PDF文件!”);
logger.debug(“CMD:” + cmd);
//更新任务状态到生成中
indiTaskDaoService.updateTaskStatus(INTASK_STATUS.GENERATE, task_id);
DBSource.get().getSession().commitAndResume();
long start = System.currentTimeMillis();
Runtime rt = Runtime.getRuntime();
Process p = null;
try {
if (!phantomjs.canExecute()) {
p = rt.exec("chmod +x " + phantomjs.getPath());
p.waitFor();
}
logger.debug("CMD_TOSTRING:" + cmd.toString());
p = rt.exec(cmd.toString());
p.waitFor();
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
logger.debug("完成导出PDF文件!");
logger.debug("运行耗时:" + (end - start) + "毫秒");