Here is the sample code for doing so:
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.document.DocumentFamily;
import org.artofsolving.jodconverter.document.DocumentFormat;
import
org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeManager;
public class TestConverter {
public static void main(String[] args) {
OfficeManager officeManager = new
DefaultOfficeManagerConfiguration().setOfficeHome("C:\\Program Files
(x86)\\OpenOffice.org
3").setConnectionProtocol(OfficeConnectionProtocol.SOCKET)
.setPortNumber(9999).setTaskExecutionTimeout(30000L).buildOfficeManager();
officeManager.start();
try {
String pageRange = "1-3"; // = "3";
DocumentFormat documentFormat =
TestConverter.getDocumentFormat(pageRange);
OfficeDocumentConverter converter = new
OfficeDocumentConverter(officeManager);
long start = System.currentTimeMillis();
converter.convert(new File(args[0]), new File(args[1]),
documentFormat);
long end = System.currentTimeMillis();
double duration = (end - start) / 1000d;
System.out.println("Conversion took: " + duration + "seconds.");
} finally {
officeManager.stop();
}
}
public static DocumentFormat getDocumentFormat(String pageRange) {
DocumentFormat format = new DocumentFormat("Portable Document
Format", "pdf", "application/pdf");
Map<String, Object> properties1 = new HashMap<String, Object>();
properties1.put("FilterName", "writer_pdf_Export");
Map<String, Object> filterData1 = new HashMap<String, Object>();
filterData1.put("PageRange", pageRange);
properties1.put("FilterData", filterData1);
format.setStoreProperties(DocumentFamily.TEXT, properties1);
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put("FilterName", "draw_pdf_Export");
Map<String, Object> filterData2 = new HashMap<String, Object>();
filterData2.put("PageRange", pageRange);
properties2.put("FilterData", filterData2);
format.setStoreProperties(DocumentFamily.DRAWING, properties2);
Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put("FilterName", "impress_pdf_Export");
Map<String, Object> filterData3 = new HashMap<String, Object>();
filterData3.put("PageRange", pageRange);
properties3.put("FilterData", filterData3);
format.setStoreProperties(DocumentFamily.PRESENTATION,
properties3);
Map<String, Object> properties4 = new HashMap<String, Object>();
properties4.put("FilterName", "calc_pdf_Export");
Map<String, Object> filterData4 = new HashMap<String, Object>();
filterData4.put("PageRange", pageRange);
properties4.put("FilterData", filterData4);
format.setStoreProperties(DocumentFamily.SPREADSHEET, properties4);
return format;