最近项目上需要每月生成月度报告上传服务器,报告还包括echarts以及表格等内容,预研了一下还是考虑使用phantomJs来将页面的报告转为pdf,下面贴一下主要代码部分
1:调用phantomjs将url转为pdf
public class Html2pdfUtil {
private static String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().replaceFirst("/","");
private static String exePath = path + "phantomjs/phantomjs";
private static String jsPath = path + "phantomjs/phantomjs.js";
public static String parseHtml2Pdf(String url) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(exePath + " " + jsPath + " " +url);
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sbf = new StringBuffer();
String tmp = "";
while ((tmp = br.readLin