我在用jacob调用office的save as pdf插件的时候,如果碰到加密的文件会要我输入密码,否则会一直停在那个地方不动,导致线程阻塞,请大神们指点一二!!
我的代码:
Dispatch docs=null;
Dispatch doc =null;
ActiveXComponent app=null;
try{
app = new ActiveXComponent("Word.Application");
app.setProperty("Visible", false);
docs = app.getProperty("Documents").toDispatch();
logger.debug("打开文档:" + inputFile);
doc = Dispatch.call(docs,"Open",inputFile,false,true).toDispatch();
logger.debug("转换文档到PDF:" + pdfFile);
File tofile = new File(pdfFile);
if (tofile.exists()){
tofile.delete();}
Dispatch.call(doc,"SaveAs",pdfFile,wdFormatPDF);
Dispatch.call(doc, "Close", false);
logger.info("转换成功!word2PDF,inputFile:"+inputFile+",outputFile:"+pdfFile);
doc.safeRelease();
}catch (Exception e) {
logger.info("转换失败!word2PDF,inputFile:"+inputFile+",outputFile:"+pdfFile);
logger.error(e);
return false;
}finally
{
docs.safeRelease();
app.invoke("Quit", new Variant[]{} );
app.safeRelease();
}
return true;
图片如下: