Conversion MS office to PDF through open source

There is always challenge to convert Microsoft office document to PDF document through open source. I had also some issue when I was working one of the projects and converting Microsoft word doc or Microsoft power point document  to pdf document through open source. Here are some steps to convert Microsoft word document or Microsoft power point document to pdf document through Java application and open source.

Prerequisite Requirements for conversion
1.)    JDK(1.5+)
2.)    Open office version-2.02+(Download from “http://www.openoffice.org/”)
3.)    jodconverter2.2.2 (Download from “http://sourceforge.net/projects/jodconverter/files/”)

Here are steps:-

1.)    install JDK(1.5+) and Open office version-2.02 in your local machine.
2.)    Go to <Open office  install folder>/ program/  folder
3.)    Run this command through MS dos window.

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

4.)    Now write the given java code and run

  1. import java.io.File;
  2. import com.artofsolving.jodconverter.DocumentConverter;
  3. import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
  4. import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
  5. import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
  6. public class MsDocToPdfUtil {
  7. public static void convertDocToPdf(){
  8. try {
  9. File in = new File("C:/test.doc");
  10. OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
  11. connection.connect();
  12. DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
  13. File outPutFile = new File("C:/test.pdf");
  14. converter.convert(in,outPutFile);
  15. connection.disconnect();
  16. }catch(Exception ex){
  17. ex.printStackTrace();
  18. }
  19. }
  20. public static void main(String[] args) {
  21. try {
  22. convertDocToPdf();
  23. } catch (Exception ex) {
  24. ex.printStackTrace();
  25. }
  26. }
  27. }