Java: JODConverter 3.x Getting Started
April 9th, 2009 by jeremychoneRequirements:
- OpenOffice installed and OpenOffice started (e.g., OpenOffice in the system tray on Windows)
- Java
Quick steps to test:
- Download the latest JODConverter 3.x from google code.
- Unzip the jar file
- Do a quick test:
java -jar lib/jodconverter-${version}.jar test.odt test.pdf
- you should see something like
C:\apps\jodconverter-3.0-beta-1>java -jar lib/jodconverter-3.0-beta-1.jar test.odt test.pdf Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start INFO: starting process with acceptString 'socket,host=127.0.0.1,port=8100' and profileDir 'C:\Users\JEREMY~1\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-8100' Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start INFO: started process; pid -1 Apr 9, 2009 12:56:47 PM net.sf.jodconverter.office.OfficeConnection connect INFO: connected: 'socket,host=127.0.0.1,port=8100' Apr 9, 2009 12:56:52 PM net.sf.jodconverter.office.OfficeConnection$1 disposing INFO: disconnected: 'socket,host=127.0.0.1,port=8100' Apr 9, 2009 12:56:53 PM net.sf.jodconverter.office.ManagedOfficeProcess doEnsureProcessExited INFO: process exited with code 0
Note: As you can see it works because it assumes that OpenOffice listen to the port 8100, which happen to be the case (how lucky!).
In a Java (Server) App:
- Copy the following .jar files in your webapp lib directory
lib/jodconverter-3.0-beta-1.jar
lib/juh-3.0.0.jar
lib/jurt-3.0.0.jar
lib/ridl-3.0.0.jar
lib/unoil-3.0.0.jar - Use the following code snippet:
OfficeManager officeManager = new ManagedProcessOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); converter.convert(sourceFile,targetFile); officeManager.stop();
Best Practice (from JODConverter group)
- OfficeManager instance can and should be shared across all
threads. It should typically be started when your webapp starts, and
stopped when the webapp stops. It can be e.g. a singleton, or a Spring
bean, or other equivalent approach of your choice. - The OfficeDocumentConverter instance can also be shared, or you can
create a different instance per thread. It doesn’t really matter,
since all conversions will be delegated to the OfficeManager anyway.
April 21st, 2009 at 10:55 am
I gave a try to JODConverter 3 -
perfect for PDF-1.4
i’d like to convert an ODT to PDF/A - tried with 2.x release of jodconverter, playing on OOo “SelectPdfVersion” property (set to 1) has no effect >> i get a PDF 1.4 doc in output.
That’s why i wanted to try jodconverter 3 >> i try to play on outputFormat.setStoreProperties (still no effect)
Any idea? Thanks
April 26th, 2009 at 6:41 pm
@Laurent, nop, sorry, I do not use it to generate PDF/A.
May 20th, 2009 at 8:12 am
Hmm thats strange.
SelectPdfVersion set to 1 should have worked.
PDFXNONE = 0
PDFX1A2001 = 1
PDFX32002 = 2
PDFA1A = 3
PDFA1B = 4
Maybe you can try with other stuff. I am trying to convert to PDF/A myself and I am not sure if I successfully do this.
Please let me know Laurent if you manage to do this correctly.
May 25th, 2009 at 12:24 am
I finally figured it out.
My problem was that I had an extra space in the pdfOption definition. Other than that, SelectPdfVersion 1 worked just fine.
Remember also to set DocumentFormat.TEXT
January 7th, 2010 at 9:30 am
In order to generate PDF/A with JODConverter 3.x I changed the definition of PDF in constructor of DefaultDocumentFormatRegistry:
DocumentFormat pdf = new DocumentFormat(”Portable Document Format”, “pdf”, “application/pdf”);
Map map = new HashMap();
map.put(”FilterName”, “writer_pdf_Export”);
PropertyValue[] aFilterData = new PropertyValue[1];
aFilterData[0] = new PropertyValue();
aFilterData[0].Name = “SelectPdfVersion”;
aFilterData[0].Value = 1;
map.put(”FilterData”, aFilterData);
pdf.setStoreProperties(DocumentFamily.TEXT, map);
March 6th, 2010 at 12:07 pm
[...] http://www.bitsandpix.com/entry/java-jodconverter-3x-getting-started/ [...]
June 22nd, 2010 at 10:56 am
@jeremy, I gave a try to JODConverter 3 -