This document implements the ability to convert a Word document file into a PDF-formatted document
First step: Download the ZIP package
(1) Jacob's official website download Jacob Compress Package
(2) website:http://sourceforge.net/projects/jacob-project/
Step two : Configure the environment and import the jar Package
(1) unzip the downloaded compressed package
(2) Import the Jacob.jar package into the project
(3) copy and paste the jacob-1.18-m2-x64.dll and jacob-1.18-m2-x86.dll files into JDK installation directory bin directory, JDK installation directory JRE of the bin directory, the system disk C:\Windows\System32 directory.
Step three: Call The static method of the Msoffice2pdf class to implement the MsOffice document conversion.
Source code for the Msoffice2pdf class
1 PackageCom.bjsxt.shangxiaofei;2 3 Importcom.jacob.activeX.ActiveXComponent;4 ImportCom.jacob.com.Dispatch;5 6 Public classMsoffice2pdf {7 8 /**9 * Convert a Word document of the specified path to a PDF document of the specified pathTen * The path here is the absolute path One * @Title: Word2pdf A * @Description: TODO (here is a word describing the effect of this method) - * @paramInputfile - * @paramPdffile the * @returnvoid return type - * @authorShang - * @date 2014-8-15 a.m. 10:25:47 - */ + Public Static voidword2pdf (String inputfile,string pdffile) { - //Open the Word application +Activexcomponent app =NewActivexcomponent ("Word.Application"); A //set Word not visible atApp.setproperty ("Visible",false); - //get all open documents in Word, return to documents object -Dispatch docs = app.getproperty ("Documents")). Todispatch (); - //call the Open method in the documents object to open the document and return the Document object that opens -Dispatch doc =dispatch.call (Docs, -"Open", in Inputfile, - false, to true + ). Todispatch (); - //Call the SaveAs method of the Document object to save the documents in PDF format the /* * Dispatch.call (Doc, $ "SaveAs",Panax Notoginseng Pdffile, - wdformatpdf//word saved as PDF macro with a value of the ); + */ A Dispatch.call (Doc, the"ExportAsFixedFormat", + Pdffile, -17//Word saves a macro in PDF format with a value of $ ); $ - - //Close Document theDispatch.call (Doc, "Close",false); - //Close the Word applicationWuyiApp.invoke ("Quit", 0); the - } Wu - About $}
View Code