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