java 生成pdf 或者image 使用 wxhtmltopdf
package com.adolph;
/**
* Created by w on 2017/4/21.
*/
public class TestWKHtmlToPdfUtil {
public String getCommand(String sourceFilePath,String targetFilePath){
String system = System.getProperty("os.name");
System.out.println(system);
if (system.contains("Windows")) {
return "D:\\wxhtml2pdf\\wkhtmltopdf.exe"+" "+sourceFilePath+" "+targetFilePath;
}
return "";
}
public String getCommandjpg(String sourceFilePath,String targetFilePath){
String system = System.getProperty("os.name");
System.out.println(system);
if (system.contains("Windows")) {
return "D:\\wxhtml2pdf\\wkhtmltoimage.exe"+" "+sourceFilePath+" "+targetFilePath;
}else {
return "";
}
}
//windows下把程序放到其他盘,否则爆错 没有足够权限写入不成功或程序执行不了
public static void main(String[] args) throws Exception{
TestWKHtmlToPdfUtil util = new TestWKHtmlToPdfUtil();
String command = util.getCommand("http://www.taobao.com", "D:\\wxhtml2pdf\\tb.pdf");
//String command = util.getCommandjpg("http://www.taobao.com", "D:\\wxhtml2pdf\\tb.jpg");
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
System.out.println("success");
}
}