Jcom之jp.ne.so_net.ga2.no_ji.jcom.JComException: createInstance() failed HRESULT=

参考资料
java应用jcom将word转pdf
http://fzh.iteye.com/blog/551003
使用的是jcom.jar日本的一个开源项目
使用版本号:JCom-2.2.0-1
步骤1:将jcom.dll放到C:\WINDOWS\system32目录下
word转换为pdf报错如下:
jp.ne.so_net.ga2.no_ji.jcom.JComException: createInstance() failed HRESULT=0x800401F3L
    at jp.ne.so_net.ga2.no_ji.jcom.IDispatch._create(Native Method)
    at jp.ne.so_net.ga2.no_ji.jcom.IDispatch.create(IDispatch.java:84)
    at jp.ne.so_net.ga2.no_ji.jcom.IDispatch.<init>(IDispatch.java:46)
    at com.dcec.call.dll.CallDll.Process(CallDll.java:14)
    at com.dcec.call.dll.CallDll.main(CallDll.java:8)

代码如下:
import jp.ne.so_net.ga2.no_ji.jcom.IDispatch;
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;

public class Office2Pdf {
	/**
	 * @param officePath          -office文件的原始路径
	 * @param pdfPath             -生成pdf的路径
	 */
	public void createPDF(String officePath, String pdfPath) throws Exception {
		ReleaseManager rm = null;
		IDispatch app = null;
		try {
			rm = new ReleaseManager();
			app = new IDispatch(rm, "PDFMakerAPI.PDFMakerApp");
			app.method("CreatePDF", new Object[] { officePath, pdfPath });			
		} catch (Exception e) {
			throw e;
		} finally {
			try {
				app = null;
				rm.release();
				rm = null;
			} catch (Exception e) {
				throw e;
			}
		}
		java.io.File f = new java.io.File(pdfPath);
		if(f.exists()){
			System.out.println("PDF创建成功");
		}else{
			System.out.println("PDF创建失败");
		}
	}

	public static void main(String[] args) throws Exception {
		
		Office2Pdf one = new Office2Pdf();			
		one.createPDF("D:\\Java\\workspace\\pdf\\test_files\\test.xls","D:\\Java\\workspace\\pdf\\test_files\\test.xls.pdf");
	}
}


解决方式:你要安装Acrobat_Pro软件且注册!,我使用的是:Acrobat_Pro_8.1.2!成功

附件上传最新版本jcom包,版本:JCom-2.2.0-1及Acrobat_Pro注册机
注意事项:你在安装Acrobat_Pro选择电话注册之后的一个页面有一个序列号,将这个序列号拷贝到注册机上,点击激活生成可用的注册码就行了,上传的文件:mcxiaoke_Keygen.zip解压后在ESET4上的报错,不管它,禁用文件防护就可!
通过测试我把C:\WINDOWS\system32目录下的jcom.dll去掉也能运行成功!

你可能感兴趣的:(java,jcom,HRESULT,createInstance,JComException)