Convert Doc to PDF

Source: Internet
Author: User

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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.