各位大虾:我想把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(DocChangePdfForJco.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (Error ex) {
// Logger.getLogger(DocChangePdfForJco.class.getName()).log(Level.SEVERE, null, ex);
return false;
} finally {
if (wps != null) {
wps.invoke("Terminate");
wps.safeRelease();
}
}
return true;
}
}
public static class PdfCreator implements Converter {
public static final int STATUS_IN_PROGRESS = 2;
public static final int STATUS_WITH_ERRORS = 1;
public static final int STATUS_READY = 0;