In the early stage, I made a PDF document reader. Recently, the company has a project that needs to convert the doc document into a PDF document.
The thread is used.
Import Java. io. file; import java.net. connectexception; import Java. util. date; import COM. artofsolving. jodconverter. documentconverter; import COM. artofsolving. jodconverter. openOffice. connection. openofficeconnection; import COM. artofsolving. jodconverter. openOffice. connection. socketopenofficeconnection; import COM. artofsolving. jodconverter. openOffice. converter. openofficedocumentconverter;/*** use the op Enoffice tool conversion to PDF * @ author zhouhuiqiang **/public class doc2pdf {Private Static Boolean doctopdf (File inputfile, file outputfile) {// connect to an OpenOffice.org instance running on port 8100 openofficeconnection connection = new socketopenofficeconnection ("127.0.0.1", 8100); try {connection. connect (); // convertsystem. out. println ("START conversion document" + inputfile. getname () + "into PDF"); documentconverter converter = New openofficedocumentconverter (connection); converter. convert (inputfile, outputfile);} catch (connectexception cex) {cex. printstacktrace (); Return false;} finally {// close the connectionif (connection! = NULL) {connection. disconnect (); connection = NULL;} return true;} class program thread extends Java. lang. thread {public file inputfile; Public file outputfile; Public void run () {doctopdf (inputfile, outputfile); system. out. println (outputfile. getname () + "file generated") ;}} public void startworkwiththread (string inputfilename, string outputfilename) {file inputfile = new file (inputfilename); file outputfile = new file (Out Putfilename); jsonthread T1 = new jsonthread (); t1.inputfile = inputfile; t1.outputfile = outputfile; t1.start ();}/*** converts a document to a PDF convertible Doc, XLS * @ Param inputfilename conversion source file, full path * @ Param outputfilename conversion destination file, full path * @ return success */public static Boolean doc2pdf (string inputfilepath, string outputfilepath) {file inputfile = new file (inputfilepath); If (inputfile. exists () {file outputfile = new file (outputfilepath); retu Rn doctopdf (inputfile, outputfile);} else {system. Out. println ("file:" + inputfilepath + "does not exist! ") ;}Return false ;}}