第一次使用wkhtmltox

==========================================================

下载地址:http://wkhtmltopdf.org/downloads.html

学习地址:http://www.tuicool.com/articles/uQbu2a
                  http://www.blogjava.net/supercrsky/articles/176525.html

-----------------------------------------------------------------------------------------------------

下载安装好后可以如图把wkhtmltox配置到环境变量中去,方便使用



测试代码:

import java.io.*;

public class HtmlToImage{

	public static void main(String[] args) {
		ProcessBuilder pb = new ProcessBuilder("wkhtmltoimage", 
			"www.baidu.com", "D:\\test.png");
		Process process;
		try{
			process = pb.start();
			BufferedReader errStreamReader = new BufferedReader(
				new InputStreamReader(process.getErrorStream()));
			System.out.println("read errStreamReader");
			String line = null;
			line = errStreamReader.readLine();
			while(line != null){
				System.out.println(line);
				line = errStreamReader.readLine();
			}
			process.destroy();
			System.out.println("destroyed process");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


测试调用命令行:以后便于使用wkhtmltox

import java.io.*;

public class CommandTest{

	public static void main(String[] args) {
		//open notepad
  //       try {   
  //               Process proc=Runtime.getRuntime().exec("notepad");   
  //       } catch (IOException e) {
  //           e.printStackTrace();   
  //       }

		//open baidu by IE
		// try {   
  //               String exeFullPathName="C:/Program Files/Internet Explorer/IEXPLORE.EXE";   
		//         String message="www.baidu.com";   
		//         String[] cmd={exeFullPathName,message}; 

		//         Process proc=Runtime.getRuntime().exec(cmd); 

  //       } catch (IOException e) {
  //           e.printStackTrace();   
  //       }

        try { 
				String[] cmd = {"cmd", "/c", "C:\\Program Files (x86)\\Tencent\\QQ\\QQProtect\\Bin\\QQProtect.exe"};
		        Runtime.getRuntime().exec(cmd); 
		        //why 这里不知道为什么不可以直接用,希望看到的会的指点下
		        //Runtime.getRuntime().exec("cmd /c start C:\\Program Files (x86)\\Tencent\\QQ\\QQProtect\\Bin\\QQProtect.exe");

        } catch (IOException e) {
            e.printStackTrace();   
        }
		
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值