jacob配置使用

jacob配置使用

**jacob介绍:**
	Jacob是Java与COM组件桥接的缩写,即JAVA-COM Bridge。通过使用Jacob类库,我们可以很
方便地在Java程序中调用COM自动化组件。

**jacob配置:**
下载jacob的,解压之后得到里面的三个文件:
1. jacob.jar															
2. jacob-1.19-x64.dll
3. jacob-1.19-x86.dll
以64位为例:
1.将jacob.jar放入项目,  将jacob.jar放入C:\Program Files\Java\jre1.8.0_241\lib\ext文件夹中
2.将jacob-1.19-x64.dll放入jdk 的bin目录和/WINDOWS/system32目录下
配置完成

**利用jacob完成word转换pdf功能**
//word转化pdf,传入转换前的文件路径(例:"E:\\a.docx")和转换后的文件路径(例:"E:\\a.pdf")
	    public static void wordToPDF(String sFilePath1,String toFilePath1) {
	        System.out.println("启动 Word...");
	        long start = System.currentTimeMillis();
	        ActiveXComponent app = null;
	        Dispatch doc = null;
	        try {
	            app = new ActiveXComponent("Word.Application");
	            app.setProperty("Visible", new Variant(false));
	            Dispatch docs = app.getProperty("Documents").toDispatch();
	            doc = Dispatch.call(docs, "Open", sFilePath).toDispatch();
	            System.out.println("打开文档:" + sFilePath);
	            System.out.println("转换文档到 PDF:" + toFilePath);
	            File tofile = new File(toFilePath);
	            if (tofile.exists()) {
	                tofile.delete();
	            }
	            Dispatch.call(doc, "SaveAs", toFilePath, // FileName
	                    17);//17是pdf格式
	            long end = System.currentTimeMillis();
	            System.out.println("转换完成..用时:" + (end - start) + "ms.");
	            
	 
	        } catch (Exception e) {
	            System.out.println("========Error:文档转换失败:" + e.getMessage());
	        } finally {
	            Dispatch.call(doc, "Close", false);
	            System.out.println("关闭文档");
	            if (app != null)
	                app.invoke("Quit", new Variant[]{});
	        }
			File file=new File(sFilePath);
			file.delete();
	        // 如果没有这句话,winword.exe进程将不会关闭
	        ComThread.Release();
	    }
jacob-1.19-x64.dll jacob-1.19-x86.dll jacob.jar LICENSE.TXT BuildingJacobFromSource.html EventCallbacks.html JacobComLifetime.html JacobThreading.html ReleaseNotes.html UsingJacob.html allclasses-frame.html allclasses-noframe.html constant-values.html deprecated-list.html help-doc.html index-all.html index.html overview-frame.html overview-summary.html overview-tree.html package-list script.js serialized-form.html stylesheet.css ComException.html ComFailException.html ComThread.html Currency.html DateUtilities.html Dispatch.html DispatchEvents.html DispatchIdentifier.html DispatchProxy.html EnumVariant.html InvocationProxy.html InvocationProxyAllVariants.html JacobException.html JacobObject.html JacobReleaseInfo.html LibraryLoader.html MainSTA.html NotImplementedException.html package-frame.html package-summary.html package-tree.html package-use.html ROT.html SafeArray.html STA.html Variant.html VariantUtilities.html VariantViaEvent.html WrongThreadException.html ComException.html ComFailException.html ComThread.html Currency.html DateUtilities.html Dispatch.html DispatchEvents.html DispatchIdentifier.html DispatchProxy.html EnumVariant.html InvocationProxy.html InvocationProxyAllVariants.html JacobException.html JacobObject.html JacobReleaseInfo.html LibraryLoader.html MainSTA.html NotImplementedException.html ROT.html SafeArray.html STA.html Variant.html VariantUtilities.html VariantViaEvent.html WrongThreadException.html ActiveXComponent.html ActiveXDispatchEvents.html ActiveXInvocationProxy.html package-frame.html package-summary.html package-tree.html package-use.html ActiveXComponent.html ActiveXDispatchEvents.html ActiveXInvocationProxy.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值