Conversion of PPT, doc conversion to PDF specific code using OpenOffice

Source: Internet
Author: User

Import Java.io.File;
Import java.io.IOException;
Import java.net.ConnectException;
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;


public class Changetopdf {

public static void Main (string[] args) {
Changetopdf c= new Changetopdf ();
File Sourcefile=new file ("c:/users/administrator/desktop/Employee leave Application Form-Raivenhua-201 May-February. doc");
File Pdffile=new file ("c:/users/administrator/desktop/Employee leave Application Form-Raivenhua-201 May-February. pdf");
C.processfile (SourceFile, pdffile);
}

/**
*
* @param pdffile the URL to generate PDF
* @param sourcefile which to generate PDF
* @return
*/
public void Processfile (File sourcefile,file pdffile) {
if (sourcefile.exists ()) {
if (!pdffile.exists ()) {
Openofficeconnection connection=new socketopenofficeconnection (8100);
try {
Connection.connect ();
Documentconverter converter=new Openofficedocumentconverter (connection);
Converter.convert (SourceFile, pdffile);
Pdffile.createnewfile ();
Connection.disconnect ();
System.out.println ("Convert to PDF format, path:" +pdffile.getpath ());
} catch (Connectexception e) {
SYSTEM.OUT.PRINTLN ("Office service not Started");
E.printstacktrace ();
} catch (IOException e) {
System.out.println ("Failed to read file");
E.printstacktrace ();
}
}else{
System.out.println ("converted to PDF, no need to convert again");
}
}else{
System.out.println ("The file to be converted does not exist!") ");
}
}
}

Conversion of PPT, doc conversion to PDF specific code using OpenOffice

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.