Tag: off requires location x64 Ice component Sys under app
Packagecom.doctopdf;ImportJava.io.File;Importcom.jacob.activeX.ActiveXComponent;ImportCom.jacob.com.ComThread;ImportCom.jacob.com.Dispatch;Importcom.jacob.com.Variant;/*** One of the best methods, but requires a window environment, and the speed is the slowest need to install Msofficeword * *:http://www.microsoft.com/zh-cn/download/details.aspx?id=7* Jacob's Bag:http://sourceforge.net/projects/jacob-project/* The extracted files * Jacob.jar placed in E:\jdk1.8.0_14\jre\lib\ext here using their own JDK installation location * Jacob.dll placed E:\jdk1.8.0_14\jre\bin here to make Install location with your own JDK * if not put or misplaced, an error will appear * Note: x86 refers to a 32-bit system * x64 refers to 64-bit system * *@authoru Y * Support Doc docx file to PDF*/ Public classDoctopdf {Private Static Final intWdformatpdf = 17;//PDF format 17 means word to PDF 44 for execl to HTML Public voidwordtopdf (String sfilename, String tofilename) {System.out.println ("Start Word ..."); LongStart = System.currenttimemillis ();//Conversion Start TimeActivexcomponent app =NULL; Dispatch Doc=NULL; Try{app=NewActivexcomponent ("Word.Application"); App.setproperty ("Visible",NewVariant (false)); Dispatch Docs= App.getproperty ("Documents")). Todispatch (); Doc= Dispatch.call (Docs, "Open", sFileName). Todispatch (); System.out.println ("Open Document ..." +sfilename); System.out.println ("Convert document to PDF ..." +tofilename); File ToFile=NewFile (tofilename); if(Tofile.exists ()) {tofile.delete (); } //Save as HTML format to temp file: 17 means word to PDF 44 for execl to HTMLDispatch.call (Doc, "SaveAs", Tofilename,//FileNamewdformatpdf); LongEnd = System.currenttimemillis ();//Conversion End TimeSYSTEM.OUT.PRINTLN ("Conversion Complete: Spents: "+ (End-start) +" Ms. "); } Catch(Exception e) {System.out.println ("========error: Document conversion failed:" +e.getmessage ()); } finally{Dispatch.call (doc,"Close",false); System.out.println ("Close Document"); if(App! =NULL) App.invoke ("Quit",Newvariant[] {}); } //without this remark, the Winword.exe process will not closecomthread.release (); } Public Static voidMain (string[] args) {doctopdf d=Newdoctopdf (); D.wordtopdf ("C:\\users\\administrator\\desktop\\ Graduation design Table structure design. docx", "C:\\spring.pdf"); }}
Need to add Jacob.jar
Java to convert Word to PDF Jacob mode