日期:2014-05-17  浏览次数:20697 次

急急急java调用WPS或pdfcreator的com接口实现doc转pdf
各位大虾:我想把word文件生成PDF,然后网上找了方法http://hacker507.iteye.com/blog/1458790
但是我的代码确不能执行

package com.sinobpo.hsda.util;

import com.jacob.activeX.ActiveXComponent;  
import com.jacob.com.Dispatch;  
import com.jacob.com.DispatchEvents;  
import com.jacob.com.Variant;  
import java.io.File;  
public class NewOfficeDocumentConverter {

public static Converter newConverter(String name) {  
        if (name.equals("wps")) {  
            return new Wps();  
        } else if (name.equals("pdfcreator")) {  
            return new PdfCreator();  
        }  
        return null;  
    }  
  
    public synchronized static boolean convert(String word, String pdf) {  
        return newConverter("wps").convert(word, pdf);  
    }  
  
    public abstract static interface Converter {  
  
        public boolean convert(String word, String pdf);  
    }  
  
    public static class Wps implements Converter {  
  
        public synchronized boolean convert(String word, String pdf) {  
            File pdfFile = new File(pdf);  
            File wordFile = new File(word);  
            ActiveXComponent wps = null;  
            try {  
                wps = new ActiveXComponent("wps.application");  
                ActiveXComponent doc = wps.invokeGetComponent("Documents").invokeGetComponent("Open", new Variant(wordFile.getAbsolutePath()));  
                doc.invoke("ExportPdf", new Variant(pdfFile.getAbsolutePath()));  
                doc.invoke("Close");  
                doc.safeRelease();  
            } catch (Exception ex) {  
               // Logger.getLogger(DocChangePdfFo