执行windows命令通过phantomjs将html文件生成pdf文件
/**
* 执行windows命令通过phantomjs将html文件生成pdf文件
* @param url html文件路径(http格式)
* @param pdfrealpath pdf文件保存路径
* @param filename pdf文件名
* @param uploadrealpath 系统配置文件内配置的下载地址
* @return
* @throws IOException
*/
public static String parseHtml2Pdf(String url, String pdfrealpath, String filename,String uploadrealpath) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(uploadrealpath+"\\tools\\phantomjs " +" " + uploadrealpath+"\\tools\\htmltopdf.js " + " " + url + " "+pdfrealpath + " "+filename );
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sbf = new StringBuffer();
String tmp = "";
while
((tmp = br.readLine()) != null) {
sbf.append(tmp);
}
String resultstr = sbf.toString();
return resultstr;
}
所需工具类phantomjs.exe 和 htmltopdf.js
链接: https://pan.baidu.com/s/1uOZ6fuUZXYbtsjUbwMSQZw 提取码: 1238