Converting ppt to pdf (and many others) from Java

date of original post on Blogger: May 28, 2008

JODConverter is a nice project that deploys OpenOffice to obtain services. It allows converting files from Office to OpenOffice, to pdf, to flash etc.
It can be embedded in a Webservice, in a Website, or driven from a Java program. The JODConverter site offers the possibility to perform online conversion.

Since NeoOffice is a branch of OpenOffice, it works also with it.

Here is a simple example (taken from the JODConverter website and completed by adding the right imports etc. – sorry the indentation is killed from Blogger’s editor).

To use it (on a Mac) you need:
– to install NeoOffice
– to download the JODConverter jars
– to start NeoOffice as a service (in a shell, execute:
/Applications/NeoOffice.app/Contents/MacOS/soffice.bin -headless -accept=”socket,port=8100;urp;”)
– compile and run the following java program (make sure that you include the jars in the library!)

package jod;
import java.io.File;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import java.net.ConnectException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
public static void main(String[] args) {
new Main();
}
Main(){
//put here the name of your source file
File inputFile = new File(“/Users/ronchet/Desktop/3.5.ppt”);
//put here the name of your destination file
File outputFile = new File(“/Users/ronchet/Desktop/3.5.pdf”);
//Note that for determining which conversion must be applied, JODConverter will use the files’extensions

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try {
connection.connect();
} catch (ConnectException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
}
}

Just a note: an alternative way to convert slides is to use (within ppt) a VBA script to export the slides into a bunch of jpgs. Here is a such script, and here another version of the same.
Also, for exporting all text, here is another VBA script.

Advertisements
Posted in Multimedia, Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: