msf word转pdf

package my;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class JacobText {

/**
* @param args
*/
public static void wordToPDF(String docfile, String toFile,int type) {   
        ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word   
        try {   
            app.setProperty("Visible", new Variant(false));   
            Dispatch docs = app.getProperty("Documents").toDispatch();
            Dispatch doc = Dispatch.invoke(   
                    docs,   
                    "Open",   
                    Dispatch.Method,   
                    new Object[] { docfile, new Variant(false),   
                            new Variant(true) }, new int[1]).toDispatch();   
            //new Variant(type),这里面的type的决定另存为什么类型的文件 
            Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {   
                    toFile, new Variant(type) }, new int[1]);   
            Variant f = new Variant(false);   
            Dispatch.call(doc, "Close", f);   
        } catch (Exception e) {   
            e.printStackTrace();   
        } finally {   
          app.invoke("Quit", new Variant[] {});   
        }   
    }
public static void main(String[] args) {
// TODO Auto-generated method stub
   //源文件全路径 
       String docfile ="C:\\Users\\Administrator\\Desktop\\新建文件夹\\aaaaa.docx"; 
//        for (int i = 0; i < 18; i++) {    
            //些路径test为实际存在的目录,s后面为要另存为的文件名 
            String toFile="C:\\Users\\Administrator\\Desktop\\新建文件夹\\aaaaa.html"; 
            wordToPDF(docfile, toFile,17); 
//         }    
}

}

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