One of another way to convert word, excel and power point to PDF is jodconverter. JODConverter can be used as java library which is also known as java OpenDocument converter. JODConverter automates all conversions supported by OpenOffice.org which are Microsoft Office to OpenDocument, and vice versa, Any format to PDFs , etc.Another important thing is that JODConverter is open source software released under the terms of the LGPL and can be downloaded from SourceForge.net.
To convert the microsoft documents to PDF first you should download the jodconverter libraries using http://sourceforge.net/projects/jodconverter/files/
import org.artofsolving.jodconverter.office.*;
import org.artofsolving.jodconverter.*;
import org.artofsolving.jodconverter.office.OfficeManager;
class convert{
public void convert(){
// inputfile and outputfile are file paths
File inputFile = new File(inputfile);
File outputFile = new File(outputfile);
OfficeManager officeManager=null;
try{
officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
officeManager.start();
officeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(inputFile, outputFile);
}catch(Exception ex){
ex.printStackTrace();
}finally{
officeManager.stop();
if(outputFile.exists()){
System.out.println("success");
}else {
System.out.println("Fail");
}
}
}//end method
}// end class
No comments:
Post a Comment