WordToXPSUtil
来源:互联网 发布:nodejs和java接口通信 编辑:程序博客网 时间:2024/06/07 12:02
package com.ibeifeng.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class WordToXPSUtil {
/**
*
* @param pro
* @return
* @throws Exception
*/
public static String readInputFromProcess(Process pro)throws Exception{
StringBuffer sb = new StringBuffer();
String line=null;
BufferedReader reader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
try {
while((line=reader.readLine())!=null){
sb.append(line).append("\r\n");
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("��ȡ���ؽ�������ʧ��");
}finally{
reader.close();
}
return sb.toString();
}
public static void wordToXPS(String src,String dest){
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec(PropertyUtil.getLocalValue("TERMIANL_CONFIG_ROOT_PATH")+"word2xps\\ConsoleApplication1.exe"+" \""+src+"\" \""+dest+"\"");
String str=readInputFromProcess(p);
System.out.println("CMD:"+str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void wordToRTF(String src,String dest){
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec(PropertyUtil.getLocalValue("TERMIANL_CONFIG_ROOT_PATH")+"word2rtf\\ConsoleApplication1.exe"+" \""+src+"\" \""+dest+"\"");
String str=readInputFromProcess(p);
System.out.println("CMD:"+str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String src="e:\\1.doc";
String dest="e:\\3.xps";
wordToXPS(src,dest);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class WordToXPSUtil {
/**
*
* @param pro
* @return
* @throws Exception
*/
public static String readInputFromProcess(Process pro)throws Exception{
StringBuffer sb = new StringBuffer();
String line=null;
BufferedReader reader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
try {
while((line=reader.readLine())!=null){
sb.append(line).append("\r\n");
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("��ȡ���ؽ�������ʧ��");
}finally{
reader.close();
}
return sb.toString();
}
public static void wordToXPS(String src,String dest){
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec(PropertyUtil.getLocalValue("TERMIANL_CONFIG_ROOT_PATH")+"word2xps\\ConsoleApplication1.exe"+" \""+src+"\" \""+dest+"\"");
String str=readInputFromProcess(p);
System.out.println("CMD:"+str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void wordToRTF(String src,String dest){
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec(PropertyUtil.getLocalValue("TERMIANL_CONFIG_ROOT_PATH")+"word2rtf\\ConsoleApplication1.exe"+" \""+src+"\" \""+dest+"\"");
String str=readInputFromProcess(p);
System.out.println("CMD:"+str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String src="e:\\1.doc";
String dest="e:\\3.xps";
wordToXPS(src,dest);
}
}