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. [Java] 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 ;/** * Convert an office File to a pdf File * @ author zhouhuiqiang **/public class Doc2Pdf {private static boolean docToPdf (File inputFile, File outputFile) using openoffice tools) {// connect to an OpenOffice.org instance running on port 8100 OpenOfficeConnection connection = new SocketOpenOfficeConnection ("127.0.0.1", 8100); try {connection. connect (); // convert System. out. println ("START conversion document" + inputFile. getName () + "into pdf"); lead E NtConverter converter = new OpenOfficeDocumentConverter (connection); converter. convert (inputFile, outputFile);} catch (ConnectException cex) {cex. printStackTrace (); return false;} finally {// close the connection if (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 output File = new File (outPutFileName); jsonthread t1 = new jsonthread (); t1.inputFile = inputFile; t1.outputFile = outputFile; t1.start ();} /*** convert a document to a pdf file in convertible doc format, xls * @ param inputFileName convert the source file, full path * @ param outPutFileName convert the target file, full path * @ return success */www.2cto.com public static boolean doc2pdf (String inputFilePath, String outPutFilePath) {File inputFile = new File (inputFilePath); if (inputFile. exists () {File OutputFile = new File (outPutFilePath); return 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.