word2pdf

import java.io.*; 
 
 
public class Main { 
    public static void main(String[] args) throws Exception{ 
        //windows 
        String cmd = "/opt/libreoffice4.3/program/soffice --headless --convert-to pdf:writer_pdf_Export /usr/pr_file/test.docx --outdir /usr/pr_file/"; 
         
        Runtime run = Runtime.getRuntime(); 
        Process p = null; 
        BufferedInputStream in = null; 
        BufferedReader inBr = null; 
        try { 
            p = run.exec(cmd); 
            in = new BufferedInputStream(p.getInputStream()); 
            inBr = new BufferedReader(new InputStreamReader(in)); 
            String lineStr; 
            while ((lineStr = inBr.readLine()) != null) 
                System.out.println(lineStr); 
            if (p.waitFor() != 0) { 
                if (p.exitValue() == 1) 
                    System.err.println("error!"); 
            }
            System.err.println("success!"); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } finally { 
            inBr.close(); 
            in.close(); 
            p.destroy(); 
        } 
    } 
}


你可能感兴趣的:(word,pdf,libreoffice,word2pdf)