java实现PDF转word,使用jacob插件

java实现PDF转word 使用jacob插件 免费而且转化效果很完善

最近开发过程中接触了这样的需求,但是网上很多都是word转PDF 很少有pdf转word的代码,于是自己研究了一下,简单实现这个功能.使用流程:
1.下载jacob插件,把jacob-1.20-x64.dll文件放到jdk的bin目录底下
2.下载并安装adobeacrobatXpro_setup.rar
3.eclipse中引入jacob.jar
4.执行代码

import org.apache.shiro.SecurityUtils;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class FileService {
    public static void main(String[]args){
    FileService dfc = new FileService();
	dfc.PDFtoWord("C:\\project\\nginx-1.21.4\\html\\layer\\upload\\contract\\91e25e0815e94688b67050939013e491-承揽合同.pdf","C:\\project\\nginx-1.21.4\\html\\layer\\upload\\contract\\91e25e0815e94688b67050939013e491-承揽合同.docx");
	}
 	public boolean PDFtoWord(String source, String target) {
	    System.out.println("PDF转DOCX开始启动...");
		File inPath = new File(source);
		File outPath = new File(target);
		//pdfActiveX PDDoc对象 主要建立PDF对象
		ActiveXComponent app = new ActiveXComponent("AcroExch.PDDoc");
		//PDF控制对象
		Dispatch pdfObject = app.getObject();
		long start = System.currentTimeMillis();
		//打开PDF文件,建立PDF操作的开始
        Dispatch.call(pdfObject, "Open", new Variant(inPath.getAbsolutePath())); 
		Variant jsObj = Dispatch.call(pdfObject, "GetJSObject");
		Dispatch.call(jsObj.getDispatch(), "SaveAs", outPath.getPath(), "com.adobe.acrobat.docx");
		app.invoke("Close");
		long end = System.currentTimeMillis();
		return true;
	    }
}

你可能感兴趣的:(java,java,开发语言,eclipse)